将操作方法中的错误消息传递给 jsp
pass error message from action method to jsp
这是我的包含业务逻辑的操作方法。我想在 jsp 中显示此操作方法的错误消息。控件转到 jsp 但错误消息不显示 up.In 我的 jsp 我有此代码来显示错误消息:
<html:errors/>
我是 struts 的新手。同样在 eclipse 中,它表示 saveErrors
方法已被弃用。我知道如何使用扩展 ActionForm
.
的 bean class 的验证方法来显示错误
public ActionForward upload(....)
{
if(noOfColumns>7)
{
errors.add(ActionErrors.GLOBAL_ERROR, new ActionMessage("error.file.maxCols"));
saveErrors(request,errors);
return mapping.findForward("uploadVIPProcess");
}
}
文档明确说明了要做什么:
Deprecated. Use saveErrors(HttpServletRequest, ActionMessages)
instead.
This will be removed after Struts 1.2.
终于找到了。这很简单:
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()));
它工作得很好:)
这是我的包含业务逻辑的操作方法。我想在 jsp 中显示此操作方法的错误消息。控件转到 jsp 但错误消息不显示 up.In 我的 jsp 我有此代码来显示错误消息:
<html:errors/>
我是 struts 的新手。同样在 eclipse 中,它表示 saveErrors
方法已被弃用。我知道如何使用扩展 ActionForm
.
public ActionForward upload(....)
{
if(noOfColumns>7)
{
errors.add(ActionErrors.GLOBAL_ERROR, new ActionMessage("error.file.maxCols"));
saveErrors(request,errors);
return mapping.findForward("uploadVIPProcess");
}
}
文档明确说明了要做什么:
Deprecated. Use
saveErrors(HttpServletRequest, ActionMessages)
instead.This will be removed after Struts 1.2.
终于找到了。这很简单:
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()));
它工作得很好:)