struts2简单国际化

前置条件:已完成简单登录例子

1、在src包下新建file文件,文件名为struts.properties

2、在src包下新建file文件,文件名为messageResource_en_US.properties

3、在src包下新建file文件,文件名为messageResource_zh_CN.properties

4、修改login.jsp文件

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>struts login</title>
  </head>
  
  <body>
  <s:i18n name="messageResource">
    <s:form action="main" method="post">
    	<table>
    		<caption>User Login</caption>
	    	<tr>
	    		<td>
	    			<s:textfield name="user.account" key="username" size="20"></s:textfield>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td>
	    			<s:password name="user.password" key="password" size="21"></s:password>
	    		</td>
	    	</tr>
	    	<tr>
	    		<td>
	    			<s:reset value="%{getText('reset')}"/>
	    			<s:submit value="%{getText('submit')}"/> 
	    		</td>
	    	</tr>
    	</table>
    </s:form>
    </s:i18n>
  </body>
</html>

5、保存启动TomCat,浏览器输入查看

猜你喜欢

转载自blog.csdn.net/zero_130/article/details/81168773