⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registaction.java

📁 Struts2 入门经典代码 供初学者研究学习
💻 JAVA
字号:
package cn.gokei.action;

import java.util.Calendar;
import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;

public class RegistAction extends ActionSupport {
	private String username;
	private String password;
	private String repassword;
	private int age;
	private Date birthday;
	private Date graduation;

	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 getRepassword() {
		return repassword;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public Date getGraduation() {
		return graduation;
	}

	public void setGraduation(Date graduation) {
		this.graduation = graduation;
	}

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

	@Override
public void validate() {
	// TODO Auto-generated method stub
if(null==username||username.length()<6||username.length()>10)
{System.out.println("valid~~~~~~");
	this.addFieldError("username","username length is less than 6 or more than 10!");
	
}
else if(null==password||password.length()<6||password.length()>10)
{
this.addFieldError("password","password's length is less than6 or more than 10");
}
else if(!repassword.equals(password))
{
	this.addFieldError("repassword", "The first password is not equals the second password!");
}
if(age<1||age>120)
{
	this.addFieldError("age", "Age is invalid!");
}
if(null==birthday)
{
	this.addFieldError("birthday", "Birthday is invalid!");
}
if(null==graduation)
{
	this.addFieldError("graduation","Graduation is invalid!");
}
if(null!=birthday&&null!=graduation)
{
	Calendar c1=Calendar.getInstance();
	c1.setTime(birthday);
	Calendar c2=Calendar.getInstance();
	c2.setTime(graduation);
	if(c2.before(c1)){
		this.addFieldError("graduation","Graduation should after Birthday");
	}
}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -