ActionError未显示 [英] ActionError not getting displayed

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

问题描述

如果Action类返回错误,我想在我的 ErrorDiv 中加载我的 Error.jsp 。我正在进行AJAX通话。

I want to load my Error.jsp in my ErrorDiv if Action class returns error. I am doing an AJAX call.

JS:

success: function(result){    
    if(result === 'success')
        alert('Database Updated Successfully!');
    else{
         $('#ErrorDiv').load('/gma/pages/Error.jsp');
    }
}

JSP:

<body>

<%
    request.setAttribute("decorator", "none");
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<s:if test="hasActionErrors()">
       <s:actionerror />
</s:if>

</body>

但是,不会显示操作错误。在firebug我检查过,回复GET Error.jsp,因为< body> < / body> 部分为空。

However, action errors are not getting displayed. In firebug I checked, response to GET Error.jsp in that the <body> </body> part comes empty.

为什么 actionError 没有显示?

编辑:

行动类

try{
slsConfigureTspThresholdRemote.setThresholdParameters(circleId, tspId, thresholdTypeFlag, thresholdParametersList);

}
catch (Exception e){    
    addActionError(e.getMessage());
    e.printStackTrace();

    result = "error";
    return ERROR;
}

struts.xml:

<action name="updateThresholdParameters"
class="cdot.oss.cmsat.gma.struts.ConfigureTspThresholdAction" method="updateThresholdParameters">

<result name="success" type="json">
    <param name="root">result</param>
</result> 

<result name="error">pages/Error.jsp</result>

目前,我正在做 $('#ErrorDiv')。html(结果); 以便我的JSP加载到 div 而不是

Presently, I am doing $('#ErrorDiv').html(result); so that my JSP get loaded in div instead of

$('#ErrorDiv').load('/gma/pages/Error.jsp');!


推荐答案

验证错误仅适用于同一请求。此外,对struts标记不起作用的Web容器也可以直接访问JSP。您应该使用操作来呈现JSP,并且该操作应该运行消息存储拦截器如果要保留先前请求的验证错误。如果要使用相同的响应返回不同的结果,可以为每个结果设置不同的状态代码。在客户端上,您可以检查Ajax响应返回的状态代码并执行相应的操作。

The validation errors are available only to the same request. Also direct access to the JSPs might be handled by the web container where the struts tags will not work. You should use an action to render a JSP and the action should run a message store interceptor if you want to keep the validation errors from the previous request. If you want to use the same response to return a different result you can set the different status code with each result. On the client you could check the status code returned by the Ajax response an do corresponding things.

success: function(data, textStatus, jqXHR){
    if(jqXHR.status == 201) {
      $('#ErrorDiv').html(data);        
    } else {
      alert('Database Updated Successfully!'); 
    }
}

在JSP中将以下内容添加到scriptlet代码

In the JSP add the following to the scriptlet code

response.setStatus(201);

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

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