import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
public class RegForm extends ActionForm {
private static final long serialVersionUID = 1L;
private String username;
private String password;
private String password2;
private String birthday;
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 getPassword2() {
return password2;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
// 校验用户名
if (this.username == null || this.username.trim().equals("")) {
ActionMessage message = newActionMessage("errors.username.null");
errors.add("username", message);
}
// 校验密码
if (this.password == null || this.password.trim().equals("")) {
ActionMessage message = newActionMessage("errors.password.null");
errors.add("password", message);
}
if(this.password2 == null || this.password2.trim().equals("")){
ActionMessage message = newActionMessage("errors.password.null");
errors.add("password2", message);
}
if(!this.password.equals(this.password2)){
ActionMessage message = newActionMessage("errors.password.diff");
errors.add("password2", message);
}
// 校验生日
if(this.birthday == null || this.birthday.equals("")){
ActionMessage message = newActionMessage("errors.birthday.null");
errors.add("birthday", message);
}else{
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
try {
df.parse(this.birthday);
} catch (ParseException e) {
ActionMessage message = newActionMessage("errors.brithday.validate");
errors.add("birthday", message);
e.printStackTrace();
}
}
return errors;
}
}
|