1

クライアント マシンの OS ロケールに従ってアプリケーションを動作させようとしています。今のところ、サーバー マシンのロケールで動作します。私は文字列フレーム作業を使用しています。サーバーには Apache Tomcat 7 を使用しています。これが私が使用した構成です。どんな助けでも感謝します。

     <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.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="basenames">
                    <list>
                        <value>i18n.api/api</value>
                        <value>i18n.exceptions/exceptions</value> 
                        <value>i18n.common/common</value>   
                        <value>i18n.login/login</value>
                        <value>i18n.plan/plan</value>
                        <value>i18n.customer/customer</value>
                        <value>org.springframework.security.messages</value> 
                        <value>org.hibernate.validator.ValidationMessages</value> 
                    </list>
                </property>
    </bean>
4

1 に答える 1

0

Spring doc のサポートされているハンドラー メソッドの引数の型を参照してください。次のように、ユーザーのロケールをハンドラー メソッドに挿入できます。

@RequestMapping("/home")
public String home(Locale userLocale) {
    // do something with userLocale

    return "home";
}

ロケールのタイプは java.util.Locale です。

ServletRequestgetLocale()のメソッドも見てください。クライアントは、リクエストに Accept-Language ヘッダーを提供する必要があります。提供しない場合、サーバーのロケールが使用されます。私はSpringがこれと同じように振る舞うと仮定しています

于 2013-06-03T06:58:39.490 に答える