Struts国际化

下面是login.jsp页面
--------------------------------------------------------------
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
    <title>login.jsp</title>
  </head>
<body>
 <form name="form" method="post" action="userCheck.do" >
     <table>
        <tr>
            <td><bean:message key="user.name"/></td>
             <td>input type="text" name="name"></div></td>
        </tr>
         <tr>
             <td<bean:message key="user.password"/></td>
             <td><input type="password" name="mm" ></td>
         </tr>
       <tr>
            <td> <input type="submit" value="提交"></td>
             <td> <input type="submit" value="重置"></td>
        </tr>
 
   </table>
  </form>
<p>
<html:link href="SwitchLocale.do?country=CN&language=zh&page=/lgoinForm.do"><font color="#CC66FF">中文</font></html:link>
<html:link href="SwitchLocale.do?country=US&language=en&page=/lgoinForm.do"><font color="#CC66FF">English</font></html:link>
</p>
 </body>
</html>

下面是中文的.properties文件-------------------------------------------
user.name=\u5e10 \u53f7:
user.password=\u5bc6 \u7801:
下面是struts-config.xml-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">

<struts-config>

<form-beans>

<form-bean name="localLanguage"
type="org.apache.struts.action.DynaActionForm">
<form-property name="language" type="java.lang.String" />
<form-property name="country" type="java.lang.String" />
<form-property name="page" type="java.lang.String" />
</form-bean>
</form-beans>
<global-forwards>
<forward name="first" path="/lgoinForm.do"/>
</global-forwards>
<action-mappings>

<action forward="/login.jsp" path="/lgoinForm" />
<action path="/SwitchLocale" type="org.apache.struts.actions.LocaleAction" name="localLanguage" >
<forward name="success" path="/login.jsp" />
</action>

</action-mappings>

<message-resources parameter="com.yourcompany.struts.config" />
</struts-config>

你可能感兴趣的:(一个最简单的例子)