public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors();
if (StringUtils.nullOrBlank(userInfo.getPasswd()) || !userInfo.getPasswd().equals(repeatedPasswd)) { errors.add("passwd", new ActionError("error.passwd.required")); }
ActionErrors errors = new ActionErrors(); saveErrors(request,errors);
sagittarius1979(射手爱狮子) 老兄说的对吧!
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors();
if (StringUtils.nullOrBlank(userInfo.getPasswd()) || !userInfo.getPasswd().equals(repeatedPasswd)) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.passwd.required")); }
return (errors); }
还是不行,我把代码贴出来请帮忙看看:ActionForm: public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if (merchantid == null || merchantid.length()<1) errors.add("usernanme", new ActionError("error.username.required"));
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (StringUtils.nullOrBlank(userInfo.getPasswd()) || !userInfo.getPasswd().equals(repeatedPasswd)) {
errors.add("passwd", new ActionError("error.passwd.required"));
}
return (errors); }
-------------------------------------------------------------------------
已经正确创建了ActionErrors对象,怎样把它放到request中?
saveErrors(request,errors);
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (StringUtils.nullOrBlank(userInfo.getPasswd()) || !userInfo.getPasswd().equals(repeatedPasswd)) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.passwd.required"));
}
return (errors); }
{
ActionErrors errors = new ActionErrors(); if (merchantid == null || merchantid.length()<1)
errors.add("usernanme", new ActionError("error.username.required"));
return errors;
}=========================
jsp中:
<html:errors/>=========================
ApplicationResources中:
error.username.required=<li>请输入用户名</li>
return (_mapping.findForward("error"));
error配置所指的jsp中<html:errors/>就出来啦
package mystruts;import org.apache.struts.action.*;
import javax.servlet.http.*;public class LogonAction extends Action {
public ActionForward perform(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
LogonForm theForm = (LogonForm) actionForm;
ActionErrors errors = new ActionErrors();
if (theForm.getUsername().equals("jbuilder") &&
theForm.getPassword().equals("borland")) {
return actionMapping.findForward("success");
} else if (theForm.getUsername().equals("jbuilder")) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.login.password"));
} else {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.login.username"));
}
if (!errors.empty()) {
saveErrors(httpServletRequest, errors);
}
return actionMapping.findForward("failure");
}
}
error.login.nullusername=<li>用户名不能为空!
error.login.password=<li>密码不正确!
errors.footer=</font></ul>
errors.header=<ul><font color="red">
你是在Action类中进行验证,我是在ActionForm中进行验证的