一. ActionForm Bean 验证 —— 处理表单验证
前提:LoginForm extends ActionForm
验证方法一:
可使用 validate() 行为
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
}
return null;
}
验证方法二:
使用 Validator 框架
二. Action 验证 —— 处理业务逻辑验证
前提:LoginAction extends Action
验证方法可包含在 execute() 行为中。
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
// TODO Auto-generated method stub
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
// TODO Auto-generated method stub
return mapping.findForward("success");
}
}
三. 优先级
ActionForm 的 validate() 方法比 Action 的 execute() 方法优先执行。