有时候需要在Action的execute()方法里面进行例如权限的验证.
举个例子,validate()是检查用户名和密码数据是否为空,当用户输入了完整信息后,执行execute(),这时若发现"用户名或密码有误",,就需要显示错误信息
举个例子,validate()是检查用户名和密码数据是否为空,当用户输入了完整信息后,执行execute(),这时若发现"用户名或密码有误",,就需要显示错误信息
public class ServerValidationAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
/*
* 权限验证
*/
ServerValidationActionForm form = (ServerValidationActionForm) actionForm;
if (!form.getPassword().equals("password")) {
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionMessage(
"errors.passwordwrong"));
saveErrors(httpServletRequest, errors);
return new ActionForward(actionMapping.getInput());
}
return actionMapping.findForward("success");
}
}