这个不是很难的。你首先要确定。你是否正确创建了ActionError对象,并且把它放到了request中去。一般没有在页面上显示错误,是因为在request中找不到ActionError对象。具体过程可以参考Struts的源码。

解决方案 »

  1.   

    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"));
            }      
     
        return (errors);  }
      

  2.   

    你首先要确定。你是否正确创建了ActionError对象,并且把它放到了request中去。
    -------------------------------------------------------------------------
    已经正确创建了ActionErrors对象,怎样把它放到request中?
      

  3.   

    ActionErrors errors = new ActionErrors();
    saveErrors(request,errors);
      

  4.   

    sagittarius1979(射手爱狮子) 老兄说的对吧!
      

  5.   

    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);  }
      

  6.   

    还是不行,我把代码贴出来请帮忙看看: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"));
            
            return errors;
      }=========================
    jsp中:
    <html:errors/>=========================
    ApplicationResources中:
    error.username.required=<li>请输入用户名</li>
      

  7.   

    楼主在什么文件中写这个public函数啊我都是在返回ActionForward的Action文件中创建ActionErrors,楼主的代码中再加上saveErrors(_request, errors);
    return (_mapping.findForward("error"));
    error配置所指的jsp中<html:errors/>就出来啦
      

  8.   

    你怎么还用这种老方法作验证呢,在struts1.1中可以使用validation中作验证了,而且提供了一些函数,比较方便,你可以参考它de document。
      

  9.   

    我也刚学,希望对你有用!
    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");
        }
    }
      

  10.   

    error.login.username=<li>用户不存在!
    error.login.nullusername=<li>用户名不能为空!
    error.login.password=<li>密码不正确!
    errors.footer=</font></ul>
    errors.header=<ul><font color="red">
      

  11.   

    kobetong(碧辉) :
    你是在Action类中进行验证,我是在ActionForm中进行验证的
      

  12.   

    现在validate已经起作用了,怎样让错误信息显示出来?