火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Struts 1.2 数据验证

Posted on 2006-04-10 21:58  剑廿三  阅读(342)  评论(0编辑  收藏  举报
一. ActionForm Bean 验证 —— 处理表单验证
 
前提:LoginForm extends ActionForm
 
验证方法一:
可使用 validate() 行为
 
public ActionErrors validate(
  ActionMapping mapping,
  HttpServletRequest request) {
  // TODO Auto-generated method stub
  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
 
  return mapping.findForward("success");
 }
 
三. 优先级
 
ActionForm 的 validate() 方法比 Action 的 execute() 方法优先执行。