我想在我的spring mvc应用程序中使用国际化。 但我无法得到如何使用它的输入。 我想要做的水木清华这样的:Spring MVC国际化
<input id="actionButton" type="submit" value='<spring:message code="LogIn"/>'/>
但按钮后,除具有标签“春天:消息代码=‘登录’”,而不是从属性文件此常数的值。我怎样才能做到这一点?
我想在我的spring mvc应用程序中使用国际化。 但我无法得到如何使用它的输入。 我想要做的水木清华这样的:Spring MVC国际化
<input id="actionButton" type="submit" value='<spring:message code="LogIn"/>'/>
但按钮后,除具有标签“春天:消息代码=‘登录’”,而不是从属性文件此常数的值。我怎样才能做到这一点?
你有没有考虑将spring:message内容存储到一个var,然后用$引用该var?
一个非常有用的教程是在这里:http://springbyexample.org/examples/basic-webapp-internationalization.html
您必须拥有的applicationContext拦截像
<mvc:interceptors>
<bean
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
您还需要
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>
我还想补充一点,在你的xml的开始你应该有这样的东西:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
为了识别诸如mvc的前缀,这是必要的。确保你有它。
我的消息_ *。properties文件位于源文件夹src/main/resources中,不在webapp中,我不知道这是否重要。
是的,这正是我所拥有的:) –
您的区域设置拦截器配置是否正确? – Reimeus
是的,如果我使用spring:message作为输入值,那么一切正常。 –
您是否考虑将spring:message内容存储到var中,然后使用EL从$引用该var? – user998692