特定语言属性文件未根据使用Spring MVC的语言选择加载

时间:2017-07-25 09:05:05

标签: java spring hibernate spring-mvc

我的计划是开发一个具有不同语言支持的Web应用程序。检查了弹簧内部化概念并做了类似的应用程序。但问题是应用程序加载了指定为defaultLocale的语言属性文件。验证了其他StackOverflow问题和其他链接,但没有成功。

spring-hibernate.xml文件snap-shot是,

<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />

<bean       
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource
">
        <property name="basenames">
            <list>
                <value>classpath:global</value>
                <!-- <value>classpath:global_en</value>  -->
                <value>classpath:db-fields</value>
                <value>classpath:package</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8" />
</bean>

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

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

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

Jsp文件是,

<style type="text/css">
select#languagedropdown {
margin: 0px 0px 0px 550px;
-webkit-appearance: none;
-moz-appearance: none;
text-indent: 1px;
text-overflow: '';
height:25px;
font-weight:bold;
}
</style>

<select id="languagedropdown"
                name="dropdown" onchange="window.location.href=this.value;">
    <option value="">&nbsp;---Language---&nbsp;</option>
    <option value="?language=en">English</option>
    <option value="?language=fa">&#1601;&#1575;&#1585;&#1587;&#1740;
        / &#1601;&#1575;&#1585;&#1587;&#1740;</option>
    <option value="?language=fr">Fran&ccedil;ais</option>
    <option value="?language=de">Deutsche</option>
    <option value="?language=ar">&#1593;&#1585;&#1576;&#1609;</option>
</select>

请帮助我们解决这个问题,尝试以下方法, http://javainsimpleway.com/714/ http://viralpatel.net/blogs/spring-3-mvc-internationalization-i18n-localization-tutorial-example/ http://www.journaldev.com/2610/spring-mvc-internationalization-i18n-and-localization-l10n-example https://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/

0 个答案:

没有答案