Hi All,
I am trying to display the helpful message to the user when error occur.
a) I have exception catching in Java as follow
AgencyDAO a = new AgencyDAO();
try {
a.updateAgency(agencyId, newAgencyCode, newAgencyName);
} catch (DAORuntimeException e) {
String message = "My Custom message";
request.setAttribute("GROUPING_EXCEPTION", new Exception(message, e));
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
}
return null;
b) AJAX call from JSP is as follow
$.ajax({
url: "updateAgency.do",
data: {
id: nRow.id,
new_code: jqInputs[0].value,
new_name: jqInputs[1].value
},
success: function() {
alert("Successfully updated.");
oTable.fnUpdate(jqInputs[0].value, nRow, 0, false);
oTable.fnUpdate(jqInputs[1].value, nRow, 1, false);
},
error: function(xhr, ajaxOptions, thrownError) {
alert("Update failed.");
restoreRow(oTable, nRow);
}
})
So in case of update fail I am getting message "Update failed." from alert. I want to show "My Custom message".
In Firebug when I check the response I am getting
<html><head><title>Apache Tomcat/6.0.20 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - My Custom message</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>My Custom message</u></p><p><b>description</b> <u>The server encountered an internal error (My Custom message) that prevented it from fulfilling this request.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.20</h3></body></html>
Is there any method ow way I can get that custom message when AJAX call fails?
Thanks
Anjib