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

📄 registaction.java

📁 利用struts2的验证框架
💻 JAVA
字号:
package com.test.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 graduate;
	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 getGraduate() {
		return graduate;
	}
	public void setGraduate(Date graduate) {
		this.graduate = graduate;
	}
	
	
	@Override
	public String execute() throws Exception {
		System.out.println("execute method invoke");
		return SUCCESS;
	}
	
	public String abc() throws Exception {
		System.out.println("abc method invoke");
		return SUCCESS;
	}
	
	public void validateAbc() {
		System.out.println("validateAbc() invoke");
	}
	
	
	@Override
	public void validate() {
		
		System.out.println("validating......");
		
//		if(null == this.getUsername() || this.getUsername().length() < 6 || this.getUsername().length() > 10){
//			this.addActionError("username error");
//		}
//		
//		if(null == this.getPassword() || this.getPassword().length() < 6 || this.getPassword().length() > 10){
//			this.addActionError("password error");
//		}
//		
//		if(null == this.getRepassword() || this.getRepassword().length() < 6 || this.getRepassword().length() > 10){
//			this.addActionError("repassword error");
//		}
//		
//		if(!this.getPassword().equals(this.getRepassword())){
//			this.addActionError("the password must be same with the repassword");
//		}
//		
//		if(this.getAge() <= 0 || this.getAge() > 150){
//			this.addActionError("the age overflow");
//		}
//		
//		
//		if(null != this.getBirthday() || null != this.getGraduate()){
//
//			Calendar c1 = Calendar.getInstance();
//			c1.setTime(this.getBirthday());
//			
//			Calendar c2 = Calendar.getInstance();
//			c2.setTime(this.getGraduate());
//			
//			if(!c1.before(c2)){
//				this.addActionError("birthday should be before graduate");
//			}
//			
//		}
		
		
	}
	
	

}

⌨️ 快捷键说明

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