Based on SPRINGMVC International Resource allocation method

Source: Internet
Author: User
Tags i18n

Based on the SPRINGMVC International Resource allocation method.

1. First, you need to configure the interceptor in Spring-mvc-servlet.xml;


<bean id= "Localechangeinterceptor" class= "Org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>


2. If you want browser adaptive language (cookie mode): Also need to be configured in Spring-mvn-servlet.xml:

2.1


<bean id= "Cookielocaleresolver" class= "Org.springframework.web.servlet.i18n.CookieLocaleResolver"/>

2.2. If you need to switch on the interface (session mode), then you need to configure:

<bean id= "Localeresolver" class= "Org.springframework.web.servlet.i18n.SessionLocaleResolver" >        < Property Name= "Defaultlocale" value= "en_US"/>    </bean>



3. Finally configure the resource file in Applicationcontext.xml

<bean id= "Messagesource" class= "Org.springframework.context.support.ResourceBundleMessageSource" >        < Property Name= "basename" value= "message"/>        <property name= "Usecodeasdefaultmessage" value= "true"/>    </bean>



4. Configure Local in the interceptor with the following code:

<mvc:interceptors>        <!--International Resource switching (automatically switched based on the locale parameter in the request parameters)--        <mvc:interceptor>            < Mvc:mapping path= "/**"/>            <ref bean= "Localechangeinterceptor"/>        </mvc:interceptor>    </mvc:interceptors>



5. Specific message_zh_cn.properties, message_en_us.properties, and other documents, placed under Classpath.


Based on SPRINGMVC International Resource allocation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.