2016-06-28 106 views
0

http://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/Spring4国际化多语言

试图遵循这一在线教程创建一个多语言的Web应用程序,我遇到的问题是,我不认为我的Spring容器找到/加载我的属性文件。我不知道什么是错的。

文件结构

enter image description here

welcome.properties

welcome.springmvc = Happy learning Spring MVC 

welcome.properties

welcome.springmvc = \u5feb\u4e50\u5b66\u4e60 Spring MVC 

的index.jsp

Language : <a href="?language=en">English</a>|<a href="?language=zh_CN">Chinese</a> 

    <h2> 
    welcome.springmvc : <spring:message code="welcome.springmvc" text="default text" /> 
    </h2> 

    Current Locale : ${pageContext.response.locale} 

应用,调度员的servlet: 我相信我的拦截器的工作,因为index.jsp的$ {} pageContext.response.locale是显示EN/ZH_CN

国际化:多郎支持

资源: http://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/ http://howtodoinjava.com/spring/spring-mvc/spring-mvc-internationalization-i18n-and-localization-i10n-example/

http://www.technicalkeeda.com/spring-tutorials/spring-mvc-internationalization-i18n-example

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

<mvc:interceptors> 
    <bean id="localeChangeInterceptor" 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="language" /> 
    </bean> 
</mvc:interceptors> 

<!-- <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" > 
    <property name="interceptors"> 
     <list> 
     <ref bean="localeChangeInterceptor" /> 
     </list> 
    </property> 
</bean> --> 


<!-- Register the welcome.properties --> 
<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basename" value="welcome" /> 
</bean> 



<!-- ViewResolver JSP --> 
<bean id="jspViewResolver" 
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="prefix" value="/WEB-INF/html/"></property> 
    <property name="suffix" value=".jsp"></property> 
</bean> 

但我的结果是的index.jsp

enter image description here

它说:“默认文本”应该真正从属性文件显示“快乐学习Spring MVC的”。

+0

请澄清您的具体问题或添加其他详细信息,以确切地突出显示您的需求。正如目前所写,很难确切地说出你在问什么。请参阅如何问问页面以获取帮助以澄清此问题。 –

+0

对不起,我编辑我的问题希望这个清楚的事情。如果你看最后截图的默认文本应该是属性文件中的“快乐学习Spring MVC”,但它显示“默认文本” –

+0

Eric,Spring MVC不够强大。它只是无法为您提供资源。 –

回答

0

我已经改变了我的应用程序 - 调度 - servlet.xml中显式状态的类路径

下班:

<!-- Register the welcome.properties --> 
<bean id="messageSource" 
class="org.springframework.context.support.ResourceBundleMessageSource"> 
<property name="basename" value="welcome" /> 
</bean> 

收件人:

<bean id="messageSource" 
    class="com.app.service.CustomMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>classpath:com/app/properties/welcome</value> 
     </list> 
    </property> 
    <property name="defaultEncoding" value="UTF-8" /> 

</bean> 
0

变化的属性文件welcome.properties

welcome_en_US.properties 

应该后

+0

尝试过但它没有工作 –

+0

你可以手动在浏览器中运行它,如localhost:8080/YourApp /?language = en – Mudassar