`
puhaitao2012
  • 浏览: 267 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

struts2 国际化的一点整理

阅读更多
个人感觉,struts2的国际化似乎要比struts1简单点,现在大致整理下流程。

welcome.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Welcome</title>
</head>

<body>
	<s:form method="post" action="login">
		<s:textfield key="username" name="uname" required="true"></s:textfield>
		<s:password key="password" name="password"></s:password>
		<s:submit key="login"></s:submit>
	</s:form>

</body>
</html>


message_zh_CN.properties

username=\u7528\u6237\u540D
password=\u5BC6\u7801
login=\u767B\u5F55
name_req=*\u8BF7\u8F93\u5165\u7528\u6237\u540D
password_req=*\u8BF7\u8F93\u5165\u5BC6\u7801


message_en_US.properties
username=UserName
password=password
login=Login
name_req=*please input your username
password_req=*please input your password


import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
    
	private String uname;
	private String password;
	
	
	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return "suc";
	}
}


struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
   <constant name="struts.custom.i18n.resources" value="message"/>
    <package name="default" namespace="/" extends="struts-default">
        <action name="login" class="asset.action.LoginAction">
            <result name="suc">/index.jsp</result>
            <result name="input">/welcome.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
    <!-- Add packages here -->
</struts>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics