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
- <!--International Configuration--
- <bean id="Messagesource"
- class="Org.springframework.context.support.ResourceBundleMessageSource" >
- <property name="basename" value="messages.messages"/>
- </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
- #message_en. Properties
- Main.title=rui Manage System
[Java]View Plaincopy
- #message_zh_CN. Properties
- Main.title=rui Management System
(2) Add the following configuration information in Dispatcher.xml
[Java]View Plaincopy
- <!--International Configuration--
- <bean id="Localeresolver" class="Org.springframework.web.servlet.i18n.SessionLocaleResolver"/>
and add the Interceptor configuration:
[Java]View Plaincopy
- <mvc:interceptors>
- <bean class="Org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
- </mvc:interceptors>
(3) Call the internationalized message in the JSP page
[Java]View Plaincopy
- <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