Spring MVC 多语言

Spring MVC 多语言的例子可以参数


http://www.journaldev.com/2610/spring-mvc-internationalization-i18n-and-localization-l10n-example


关键是设置:

<beans:bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
		<beans:property name="basename" value="classpath:app.ApplicationResources"> </beans:property>
	</beans:bean>

	<beans:bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
	   <beans:property name="defaultLocale" value="en"></beans:property>
	 </beans:bean>

	 <interceptors>
		<beans:bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
			<beans:property name="paramName" value="locale" />
		</beans:bean>
	</interceptors>

这是通过动态化进行设置的


如果在不浏览器本地语言的情况下,默认设置成其它语言

如(web.xml)可以设置 :

<context-param>
	  <param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
	  <param-value>en</param-value>
	</context-param>
如果想动态加载

<fmt:setLocale value="en_US" scope="session"/>

具体请参考:

https://stackoverflow.com/questions/6126542/how-to-set-jstl-locale-from-java-code

猜你喜欢

转载自blog.csdn.net/xiazou/article/details/72898606