目录
登录例子
区别
时间属性
验证机制
这篇博客主要介绍使用struts框架常用的验证方式。
代码解释:
第一种:重写ActionForm的validate方法。
在actionForm中需要验证的都是表单的验证而非业务的验证。比如用户名非空,密码为数字,日期为时间格式等等。在validate方法中,返回ActionErrors信息,然后在错误页打印错误信息。
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors=new ActionErrors();
if(username==null||"".equals(username)){
errors.add(username, new ActionMessage("error.username",username));
}
if(password==null || "".equals(password)){
errors.add("password",new ActionMessage("error.password",password));
}
if(!(birthday instanceof Date)){
errors.add("birthday",new ActionMessage("error.birthday",birthday));
}
return errors;
}
代码解释:
&nb