ActionError not getting displayed

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>

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

Why are actionError not getting displayed?

EDIT:

Action Class:

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>

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

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

Answers:

Answer

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!'); 
    }
}

In the JSP add the following to the scriptlet code

response.setStatus(201);

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.