表单校验和业务逻辑校验

表单校验:请求参数->ActionForm->ActionForm.validate->表单校验错误返回errors->reguser.jsp->显示错误信息。

业务逻辑校验:请求参数->ActionForm->ActionForm.validate->表单校验成功则调用Action.execute方法->逻辑校验错误->产生errors->返回reguser.jsp显示错误信息。


public class RegUser extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
UserForm userForm = (UserForm)form;
ActionMessages errors = new ActionMessages();
if(userForm.getUser().getUsername().trim().equals("wxx")) {
errors.add("username", new ActionMessage("error.username.wrong"));
/* request.setAttribute(Globals.ERROR_KEY, errors);
return mapping.findForward("failure"); */
[color=blue][b]saveErrors[/b][/color](request, errors);
return mapping.getInputForward();
}
return mapping.findForward("success");
}
}


<action input="/WEB-INF/user/regUser.jsp" name="userForm" path="/RegUser" type="cn.user.strutsdemo.actions.RegUser">
<forward name="success" path="/WEB-INF/user/main.jsp"></forward>
</action>


[b][color=blue]Action提供两个方法来保存消息:saveErrors,saveMessage,前者:jsp画面<html:errors>可以取到错误消息,后者<html:messages>取到的是非错误消息,相当于一个是好人一个是坏人。[/color][/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值