當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。