1.配置DispatcherServlet-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- Configure auto-scanned packages-->
<context:component-scan base-package="com.hetaoo.controller"></context:component-scan>
<!-- Configure internationalized resource files-->
<bean id=" messageSource " class="org.springframework.context.support.ResourceBundleMessageSource">
<!-- The red place above caused me an error-->
<property name="basename" value="i18n"></property>
</bean>
<!-- Configure the view parser: how to parse the return value of the handler method into the actual physical view -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- Configure internationalized resource files
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="i18n"></property>
</bean>-->
</beans>
2. Write the i18n.properties configuration file
i18n.username=Username i18n.password=Password
i18n_zh_CN.properties file
i18n.username=\u7528\u6237\u540D i18n.password=\u5BC6\u7801
i18n_en_US.properties
i18n.username=Username i18n.password=Password
3. Write the jsp page
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <!--Without this tag there is no jstl jar package--> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <fmt:message key="i18n.username"></fmt:message> <br><br> <fmt:message key="i18n.password"></fmt:message> <br><br> </body> </html>
4. Just write a controller to return to the above jsp page