简体   繁体   English

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

[英]pass error message from action method to jsp

This is my action method containing the business logic. 这是我包含业务逻辑的操作方法。 I want to show error message from this action method in the jsp. 我想在jsp中显示此操作方法的错误消息。 The control goes to the jsp but the error message does not show up.In my jsp i have this code to display error message: 控件转到jsp,但错误消息未显示。在我的jsp中,我有以下代码来显示错误消息:

<html:errors/>

I am new to struts. 我是Struts的新手。 Also in eclipse it says that saveErrors method is deprecated. 同样在eclipse中,它说不建议使用saveErrors方法。 i know how to display errors using validate method of the bean class which extends ActionForm . 我知道如何使用扩展ActionForm的bean类的validate方法显示错误。

 public ActionForward upload(....)
    {
     if(noOfColumns>7)
                  {
                      errors.add(ActionErrors.GLOBAL_ERROR, new ActionMessage("error.file.maxCols")); 
                     saveErrors(request,errors);

                     return mapping.findForward("uploadVIPProcess");
                  }
    }

The docs explicitly state what to do: 该文档明确说明了该怎么做:

Deprecated . 不推荐使用 Use saveErrors(HttpServletRequest, ActionMessages) instead. 请使用saveErrors(HttpServletRequest, ActionMessages)

This will be removed after Struts 1.2. 在Struts 1.2之后将删除它。

finally found it. 终于找到了。 This was very simple: 这很简单:

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

so the only difference is instead of: 所以唯一的区别是:

return mapping.findForward("uploadVIPProcess");

I changed it to: 我将其更改为:

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

and it's working just fine:) 并且工作正常:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM