i18n不使用spring mvc和tiles支持

时间:2016-02-05 12:34:25

标签: spring


sudo: /etc/sudoers is world writable
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

...

以上是我的spring-servlet xml文件..在我的jsp中使用它

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
            xmlns:context="http://www.springframework.org/schema/context"
            xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
            xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">

            <context:component-scan base-package="in.controllers" />

            <context:annotation-config />

            <!-- This tag adds DefaultAnnotationHandlerMapping. If <mvc:resources /> 
                is tag is used, it will add the ResourceHttpRequestHandler, which will break 
                the existing default handlers added by the spring. So it is required to add 
                the handler mapping explicitly or add <mvc:annotation-driven /> tag. -->
            <mvc:annotation-driven />

            <mvc:resources location="/static/" mapping="/static/**" />

            <!-- <bean id="viewNameTranslator" -->
            <!-- class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" 
                /> -->

        <!--        If you do not register any “localeResolver”, the default AcceptHeaderLocaleResolver will be used,  -->
        <!--        which resolves the locale by checking the accept-language header in the HTTP request. -->

            <bean id="multipartResolver"
                class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />

            <bean id="viewResolver"
                class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <!--        <property name="order" value="0" /> -->
                <property name="viewClass"
                    value="org.springframework.web.servlet.view.tiles3.TilesView" />
            </bean>
            <bean id="tilesConfigurer"
                class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
                <property name="definitions" value="/WEB-INF/tiles-defs.xml" />
            </bean>
            <!-- for bilingual ..these are the settings ....starts... -->

            <bean id="messageSource"
                class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
                <property name="basename" value="/WEB-INF/messages/messages" />
                <property name="defaultEncoding" value="UTF-8" />
            </bean>

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

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

            <!-- the “order” property, where the lower order value has the higher priority. -->
            <bean id="handlerMapping"
                class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <!--        <property name="order" value="1" /> -->
                <property name="interceptors">
                    <ref bean="localeChangeInterceptor"></ref>
                </property>
            </bean>
            <!-- for bilingual ..these are the settings ....ends... -->
        </beans>

i18n没有工作..请帮助..所有的消息属性文件都存在..但仍然i18n不工作..请帮助..

1 个答案:

答案 0 :(得分:0)

您可以更改您的区块代码:

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

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="kan"></property>
</bean>
<!-- the “order” property, where the lower order value has the higher priority. -->
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <!--        <property name="order" value="1" /> -->
    <property name="interceptors">
         <ref bean="localeChangeInterceptor"></ref>
    </property>
</bean>

使用以下代码:

<!-- Define locale resolver -->
<bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver"
        p:defaultLocale="kan" p:cookieName="languageSession" />
<!-- Register the interceptors -->
<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="locale"/>
</mvc:interceptors>