当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletRequest.getLocale方法代码示例

本文整理汇总了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;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:18,代码来源:IndexController.java

示例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;
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:UserPreferenceServiceImpl.java

示例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);
    }

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:RequestProcessor.java

示例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();
		}

	};
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:19,代码来源:LanguageProvider.java

示例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());
        }
    };
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:CasManagementWebAppConfiguration.java

示例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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:16,代码来源:CasWebAppConfiguration.java

示例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;
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:AcceptLanguageHeaderResolver.java

示例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();
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:11,代码来源:GeneratedValidationJavaScriptHandler.java

示例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();
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:16,代码来源:ValidatorContext.java

示例10: resolveLocale

import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public Locale resolveLocale(HttpServletRequest request) {
	defaultLocale = request.getLocale();
	return defaultLocale;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:5,代码来源:Messages.java

示例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 );
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:7,代码来源:I18N.java

示例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));
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:61,代码来源:ServletRequestCopy.java


注:本文中的javax.servlet.http.HttpServletRequest.getLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。