转: 应用Struts 2 的国际化支持特性(7)下
<%@?page?contentType="text/html;charset=UTF-8"?language="java"?%>
<%@?taglib?prefix="s"?uri="/struts-tags"?%>
<html>
<head>
<title><s:text?name="regsuccess"/></title>
<s:head?/>
</head>
<body>
<table>
<h2><s:text?name="username"/>:<s:property??value="username"?/></h2>
<h2><s:text?name="password1"/>:<s:property??value="password1"?/></h2>
<h2><s:text?name="birthday"/>:<s:property??value="birthday"?/></h2>
</table>
</body>
</html>
package?ch4;
import?java.util.Date;
import?com.opensymphony.xwork2.ActionSupport;
public?class?Reg?extends?ActionSupport?{
????//定义用户名属性
????private?String?username;
????//定义处理信息:注意与http中的msg名称不同
????private?String?mymsg;
????//定义密码属性
????private?String?password1;
????//定义确认密码
????private?String?password2;
????//定义生日属性
????private?Date?birthday;
????public?String?execute()?throws?Exception?{
????????//判断用户输入参数
????????if?(username?!=?null?&&?getPassword1().equals(getPassword2())
????????????????&&?!getUsername().trim().equals(""))?{
????????????//打印国际化信息
????????????System.out.println(getText("username")?+?":"?+?username);
????????????System.out.println(getText("password1")?+?":"?+?password1);
????????????System.out.println(getText("birthday")?+?":"?+?birthday);
????????????return?SUCCESS;
????????}?else?{
????????????return?INPUT;
????????}
????}
????//getter和setter方法
????public?String?getUsername()?{
????????return?username;
????}
????public?void?setUsername(String?username)?{
????????this.username?=?username;
????}
????public?String?getMymsg()?{
????????return?mymsg;
????}
????public?void?setMymsg(String?mymsg)?{
????????this.mymsg?=?mymsg;
????}
????public?String?getPassword1()?{
????????return?password1;
????}
????public?void?setPassword1(String?password1)?{
????????this.password1?=?password1;
????}
????public?String?getPassword2()?{
????????return?password2;
????}
????public?void?setPassword2(String?password2)?{
????????this.password2?=?password2;
????}
????public?Date?getBirthday()?{
????????return?birthday;
????}
????public?void?setBirthday(Date?birthday)?{
????????this.birthday?=?birthday;
????}
}
??????????????
Action中可以使用ActionSupport类提供的getText(String?aTextName)方法来获得国际化信息,证实了前面所讲的国际化拦截器将用户请求参数中的Locale值存入了当前session中,Action正是获得了与Locale相关联的国际化信息资源。
?