本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getLocale方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getLocale方法的具体用法?Java HttpServletRequest.getLocale怎么用?Java HttpServletRequest.getLocale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getLocale方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: index
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = ACTION_INDEX, method = RequestMethod.POST)
public String index(
@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String username,
Map<String, Object> map, HttpServletRequest request,
HttpServletResponse response) {
defaultLocale = request.getLocale();
Shiro shiro = Shiro.get();
if (null != shiro && null != username
&& shiro.getEmail().equals(username)) {
return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_REPOS
+ ACTION_LIST;
}
String message = exception(request);
map.put("message", message);
map.put("username", username);
return PAGE_INDEX;
}
示例2: getPreferredLocale
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public Locale getPreferredLocale(HttpServletRequest request)
{
Locale locale = null;
if( CurrentInstitution.get() != null && !CurrentUser.isGuest() && !CurrentUser.getUserState().isSystem() )
{
// Is locale selected as a user preference?
locale = getLocale();
}
if( locale == null && request != null )
{
// Is it part of the browser request?
locale = request.getLocale();
}
if( locale == null )
{
return Locale.getDefault();
}
return locale;
}
示例3: processLocale
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* <p>Automatically select a <code>Locale</code> for the current user, if requested.
* <strong>NOTE</strong> - configuring Locale selection will trigger
* the creation of a new <code>HttpSession</code> if necessary.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*/
protected void processLocale(HttpServletRequest request,
HttpServletResponse response) {
// Are we configured to select the Locale automatically?
if (!moduleConfig.getControllerConfig().getLocale()) {
return;
}
// Has a Locale already been selected?
HttpSession session = request.getSession();
if (session.getAttribute(Globals.LOCALE_KEY) != null) {
return;
}
// Use the Locale returned by the servlet container (if any)
Locale locale = request.getLocale();
if (locale != null) {
if (log.isDebugEnabled()) {
log.debug(" Setting user locale '" + locale + "'");
}
session.setAttribute(Globals.LOCALE_KEY, locale);
}
}
示例4: createContext
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public Language createContext(HttpServletRequest httpServletRequest) {
return new Language() {
@Override
public Stream<Locale> getLocales() {
Enumeration<Locale> locales = httpServletRequest.getLocales();
return Collections.list(locales).stream();
}
@Override
public Locale getPreferredLocale() {
return httpServletRequest.getLocale();
}
};
}
示例5: localeResolver
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Bean
public CookieLocaleResolver localeResolver() {
return new CookieLocaleResolver() {
@Override
protected Locale determineDefaultLocale(final HttpServletRequest request) {
final Locale locale = request.getLocale();
if (StringUtils.isEmpty(casProperties.getMgmt().getDefaultLocale())
|| !locale.getLanguage().equals(casProperties.getMgmt().getDefaultLocale())) {
return locale;
}
return new Locale(casProperties.getMgmt().getDefaultLocale());
}
};
}
示例6: localeResolver
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Bean
public CookieLocaleResolver localeResolver() {
final CookieLocaleResolver bean = new CookieLocaleResolver() {
@Override
protected Locale determineDefaultLocale(final HttpServletRequest request) {
final Locale locale = request.getLocale();
if (StringUtils.isBlank(casProperties.getLocale().getDefaultValue())
|| !locale.getLanguage().equals(casProperties.getLocale().getDefaultValue())) {
return locale;
}
return new Locale(casProperties.getLocale().getDefaultValue());
}
};
return bean;
}
示例7: resolveLocale
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public Locale resolveLocale(final HttpServletRequest request) {
if (Utils.isNotEmpty(request.getHeader("Accept-Language")))
return request.getLocale();
else
return null;
}
示例8: getLocale
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected Locale getLocale(HttpServletRequest request) {
String locale = request.getParameter(WebContext.PARAMETER_LOCALE);
if (StringUtils.hasText(locale)) {
try {
return LocaleUtils.toLocale(locale);
} catch (IllegalArgumentException e) { }
}
return request.getLocale();
}
示例9: getLocale
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private Locale getLocale() {
final WebContext context = WebContextThreadStack.get();
if (context == null) {
return Locale.getDefault();
}
final HttpServletRequest request = context.getHttpServletRequest();
final ValidatorConfig validatorConfig = this.validatorFactory.getValidatorConfig();
final String locale = request.getParameter(validatorConfig.getLanguageParameterName());
if (StringUtils.hasText(locale)) {
try {
return LocaleUtils.toLocale(locale);
} catch (IllegalArgumentException e) { }
}
return request.getLocale();
}
示例10: resolveLocale
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public Locale resolveLocale(HttpServletRequest request) {
defaultLocale = request.getLocale();
return defaultLocale;
}
示例11: getWebInstance
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public static I18N getWebInstance( HttpServletRequest req ) {
locale=req.getLocale();
ResourceBundle bundle=ResourceBundle.getBundle("Ralasafe_Web", locale);
return new I18N( bundle );
}
示例12: ServletRequestCopy
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public ServletRequestCopy(HttpServletRequest request) {
this.servletPath = request.getServletPath();
this.contextPath = request.getContextPath();
this.pathInfo = request.getPathInfo();
this.requestUri = request.getRequestURI();
this.requestURL = request.getRequestURL();
this.method = request.getMethod();
this.serverName = request.getServerName();
this.serverPort = request.getServerPort();
this.protocol = request.getProtocol();
this.scheme = request.getScheme();
/*
* have to comment out below two lines as otherwise web socket will
* report UnSupportedOperationException upon connection
*/
//this.characterEncoding = request.getCharacterEncoding();
//this.contentType = request.getContentType();
//this.requestedSessionId = request.getRequestedSessionId();
this.characterEncoding = null;
this.contentType = null;
this.requestedSessionId = null;
this.locale = request.getLocale();
this.locales = request.getLocales();
this.isSecure = request.isSecure();
this.remoteUser = request.getRemoteUser();
this.remoteAddr = request.getRemoteAddr();
this.remoteHost = request.getRemoteHost();
this.remotePort = request.getRemotePort();
this.localAddr = request.getLocalAddr();
this.localName = request.getLocalName();
this.localPort = request.getLocalPort();
this.pathTranslated = request.getPathTranslated();
this.principal = request.getUserPrincipal();
HttpSession session = request.getSession(true);
httpSession = new HttpSessionCopy(session);
String s;
Enumeration<String> e = request.getHeaderNames();
while (e != null && e.hasMoreElements()) {
s = e.nextElement();
Enumeration<String> headerValues = request.getHeaders(s);
this.headers.put(s, headerValues);
}
e = request.getAttributeNames();
while (e != null && e.hasMoreElements()) {
s = e.nextElement();
attributes.put(s, request.getAttribute(s));
}
e = request.getParameterNames();
while (e != null && e.hasMoreElements()) {
s = e.nextElement();
parameters.put(s, request.getParameterValues(s));
}
}