Spring MVC Internationalization

Source: Internet
Author: User

This article is based on spring MVC annotations-let Spring run. The internationalization mentioned in this paper is one of the solutions to the internationalization of spring.

(1) Add the following configuration information in Applicationcontext.xml:

[Java]View Plaincopy
    1. <!--International Configuration--
    2. <bean id="Messagesource"
    3. class="Org.springframework.context.support.ResourceBundleMessageSource" >
    4. <property name="basename" value="messages.messages"/>
    5. </bean>

In the messages.messages mentioned in the preceding code, the previous messages is a folder under SRC, and the latter messages is all the files that begin with messages and end with properties, such as Messages_zh_ Cn.properties or messages_en.properties, these files are files that are configured for internationalized information, with the following information:

[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 Management System



(2) Add the following configuration information in Dispatcher.xml

[Java]View Plaincopy
    1. <!--International Configuration--
    2. <bean id="Localeresolver" class="Org.springframework.web.servlet.i18n.SessionLocaleResolver"/>


and add the Interceptor configuration:

[Java]View Plaincopy
    1. <mvc:interceptors>
    2. <bean class="Org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
    3. </mvc:interceptors>

(3) Call the internationalized message in the JSP page

[Java]View Plaincopy
    1. <fmt:message key="Main.title"/>



(4) Access to the system, only the initial access to the system, the address block added "? locale=en" to access the English site. Note that when you access the first page of the system, you add it, and the thread is no longer added.

Spring MVC Internationalization

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.