操作错误未显示在JSP上 [英] Action errors are not shown on the JSP

查看:107
本文介绍了操作错误未显示在JSP上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在Action类中添加操作错误并将其打印在JSP页面上.

I have tried adding action errors in the Action class and printing them on the JSP page.

发生异常时,它将进入catch块,并在控制台中打印插入异常时出现错误,请联系管理员".

When an exception occurred, it is going into the catch block and it is printing "Error in inserting the Exception, Contact the Admin", in console.

在catch块中,我已将其添加到addActionError()中,并尝试在jsp页面中进行打印...
,但该消息未显示在jsp页面中.

In the catch block, I've added it with addActionError(), and I've tried printing it in jsp page...
but the message is not shown in jsp page.

我可能缺少什么或做错了什么?

What I may be missing or doing wrong ?

支柱映射:

<action name="dataUpdate" class="foo.bar.myAction" method="updation">
    <result name="success" type="redirectAction">
        ../Aggregator/redirectToDataUpdate
    </result>
</action>

动作类:

public String updation() throws JiffieTransactionException{
    try {
        // do stuff...
    } catch (NumberFormatException e) {
        addActionError("Error in inserting the Exception, Contact the Admin");
        System.out.println("Error in inserting the Exception, Contact the Admin");
        e.printStackTrace();
    }
    return SUCCESS;
}

用于打印操作错误的JSP代码:

JSP code for printing action errors:

<s:if test="hasActionErrors()">
    <br></br>
    <div class="errors">
        <font color="red">
            <s:actionerror/>
        </font>
    </div>
</s:if>

推荐答案

当您执行redirectAction时,将创建一个新的Request,并因此创建所有actionMessages,actionErrors以及所有其他参数(未明确声明要传递)在struts配置中)丢失了.

When you perform a redirectAction, a new Request is created, and hence all the actionMessages, actionErrors, along with all the other parameters (not expressly declared to be passed in the struts config) are lost.

然后

  • 使用默认的调度程序结果,而不是 MessageStore拦截器来保存重定向中的错误和消息或
  • 在出现错误的情况下返回不同类型的调度程序结果,例如. ERROR:

  • Use a default dispatcher result instead of a redirectAction result, or
  • use the MessageStore Interceptor to preserve errors and messages across the redirects, or
  • return a different result of type dispatcher in case of errors, eg. ERROR:

<action name="dataUpdate" class="foo.bar.myAction" method="updation">
    <result name="success" type="redirectAction">....redirectToDataUpdate</result>
    <result name="error">previousPage.jsp</result>
</action>

public String updation() {
    try {
        // do stuff...
        return SUCCESS;
    } catch (NumberFormatException e) {
        addActionError("Errors... ");
        e.printStackTrace();
        return ERROR;
    }
}

这篇关于操作错误未显示在JSP上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆