• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error Message.

 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sending the Application specific error message using the code below.
int statusCode;
String message;
....
....
....
System.out.println("Status code is : " + statusCode + "msg : " + message);
response.sendError(statusCode, message);
Both the status code and message get printed correctly.
In the JSP I use the follwoing code.
<%@ page import="com.ibm.websphere.servlet.error.*" %>
<%
ServletErrorReport error = (ServletErrorReport) request.getAttribute(ServletErrorReport.ATTRIBUTE_NAME);
String errMsg = error.getMessage();
int errCode = error.getErrorCode();
System.out.println("Error Message : " + errMsg);
System.out.println("Error Code : " + errCode);
%>
To My Surprise the message gets thru but not the error code. Am i missing some thing here.Please help me.
Thanks
Praveen
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are a bit confused with regards to the purpose of HttpServletResponse.sendError(int sc, String message). Here is the description from Javadocs:
public void sendError(int sc, java.lang.String msg):
Sends an error response to the client using the specified status clearing the buffer. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Therefore the sendError() method is used to communicate an error to the client not to your code. Furthermore, you are checking the request for you error information in the JSP but at no point do you show code that had set information in the request. Websphere itself may do this but then it is not a standard part of the Servlet/JSP Specifications.
Since this question is really about Servlets (though maybe it is more Websphere) I am moving it to the Servlets Forum for further discussion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!