struts2 国际化

目录:




首页 Register.jsp :

  <body>
 	 <center>
		  <s:form id="id" action="Register">
		    <s:textfield name="username" key="username"/>
		  	<s:password name="password" key="password"/>
		  	<s:password name="confirmpassword" key="confirmpassword"/>
		  	<s:textfield name="email" key="email"/>
		  	<s:textfield name="birth" key="birth"/>
		  	<s:submit name="submit" key="submit"/>
		    <s:reset name="reset" key="reset"/>
		   </s:form>
	</center>
  </body>

提交到action-----Register:
package com.zhbit.action;

import java.sql.*;
import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;
import com.zhbit.DB.DBCon;

public class RegAction extends ActionSupport {

	private String username;
	private String password;
	private String confirmpassword;
	private String email;
	private Date birth;
	
	public RegAction() {};
	
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

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

	public String getConfirmpassword() {
		return confirmpassword;
	}

	public void setConfirmpassword(String confirmpassword) {
		this.confirmpassword = confirmpassword;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getBirth() {
		return birth;
	}

	public void setBirth(Date birth) {
		this.birth = birth;
	}
	
	public String execute() throws Exception {
		//连接数据库,将表单数据存入数据库中
		Connection conn;
		PreparedStatement pstmt;
		String sql = "insert into user values(?,?,?,?)";
		conn = DBCon.getConn();
		pstmt = DBCon.getPStmt(conn, sql);
		pstmt.setString(1, username);
		pstmt.setString(2, password);
		pstmt.setString(3, email);	
		// 用Timestamp转换为mysql时间
		pstmt.setTimestamp(4, new Timestamp(birth.getTime()));
		pstmt.executeUpdate();
		return SUCCESS;
	}
}



资源配置文件:

struts.properties:

struts.custom.i18n.resources=globalMessages

globalMessages_en_US.properties: (以key-value形式存入)

username=UserName
password=Password
confirmpassword=Password
email=Email
birth=Birthday
submit=Regist
reset=Reset
title=Struts2_Register
head=SystemRegistration


globalMessages_zh_CN.properties:




eclipse(可能要装插件,主要处理文字转义问题)转换后,本质为:

username=\u7528\u6237\u540D
confirmpassword=\u5BC6\u7801
submit=\u6CE8\u518C
reset=\u91CD\u7F6E
email=Email
birth=\u751F\u65E5
password=\u5BC6\u7801
title=Struts2_\u6CE8\u518C
head=\u7CFB\u7EDF\u6CE8\u518C

注意:

资源文件位置 /src/***

这样就可以实现,一个浏览页面,多国语言的实现了!



 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值