zoukankan      html  css  js  c++  java
  • Spring MVC国际化

    本文基于Spring MVC 注解-让Spring跑起来。本文提到的国际化是Spring实现国际化的方案之一。

            (1) 在applicationContext.xml中添加以下配置信息:

    [java] view plaincopy
     
    1.        <!-- 国际化配置 -->  
    2. <bean id="messageSource"  
    3.     class="org.springframework.context.support.ResourceBundleMessageSource">  
    4.     <property name="basename" value="messages.messages" />  
    5. </bean>  

            上述代码中提到的messages.messages中,前一个messages是src下的一个文件夹,后一个messages是所有以messages开头的,以properties结尾的文件,如messages_zh_CN.properties或messages_en.properties,这些文件即是配置国际化信息的文件,其信息分别如下:

    [java] view plaincopy
     
    1. #message_en.properties  
    2. main.title=RUI manage system  
    [java] view plaincopy
     
    1. #message_zh_CN.properties  
    2. main.title=RUI管理系统  



            (2) 在dispatcher.xml中添加以下配置信息

    [java] view plaincopy
     
    1. <!-- 国际化配置 -->  
    2. <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />  


            并添加拦截器配置:

    [java] view plaincopy
     
    1. <mvc:interceptors>  
    2.     <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />  
    3. </mvc:interceptors>  

            (3) 在jsp页面中调用国际化后的信息

    [java] view plaincopy
     
    1. <fmt:message key="main.title" />  



            (4) 访问系统,只需要在初次访问系统时,在地址拦上添加"?locale=en"即可访问英文网站。注意,访问系统的第一个页面时添加即可,后绪可不再添加。

  • 相关阅读:
    SQL数据库inner join ,join,left join,full join(转)
    CSRF攻击(转)
    BZOJ1853: [Scoi2010]幸运数字
    BZOJ1935: [Shoi2007]Tree 园丁的烦恼
    BZOJ3289Mato的文件管理
    树状数组
    莫队算法
    如何在win上用Linux编c++
    Hash的应用
    关于指数循环节的证明
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/4108335.html
Copyright © 2011-2022 走看看