从操作方法传递错误消息到jsp

时间:2015-07-27 12:17:30

标签: java jsp struts-1

这是我的包含业务逻辑的action方法。我想在jsp中显示来自此操作方法的错误消息。控件转到jsp但错误消息没有显示出来。在我的jsp中我有这段代码显示错误信息:

<video muted="true" ... >  

我是struts的新手。同样在eclipse中,它表示不推荐使用<html:errors/> 方法。我知道如何使用扩展saveErrors的bean类的validate方法来显示错误。

ActionForm

2 个答案:

答案 0 :(得分:0)

文档明确说明要做什么:

  

<强>已过时即可。请改用saveErrors(HttpServletRequest, ActionMessages)

     

这将在Struts 1.2之后删除。

答案 1 :(得分:0)

终于找到了它。这很简单:

public ActionForward upload(....)
    {
              errors.add(ActionErrors.GLOBAL_ERROR, new ActionMessage("error.file.maxCols")); 
              saveErrors(request,errors);
              return (new ActionForward(mapping.getInput()));
    }

所以唯一的区别不是:

return mapping.findForward("uploadVIPProcess");

我把它改为:

return (new ActionForward(mapping.getInput()));

它的工作正常:)