• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Error Message.

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing Praveen,
Please take a quick look at the naming policy and edit your profile accordingly. In particular, we don't allow initials for last names, though we don't mind if you use an initial for your first name. Thanks.
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well..I would think so. But I am still confused how this code would have worked in WAS 3.5.3 where i was able to execute the same code. Is there any other way i could pass the error message back to the user. I am also sending the log.
[8/21/03 15:27:17:594 EDT] 7e50fe35 WebGroup E SRVE0026E: [Servlet Error]-[TestServlet]: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: Testing Error Messaging
at com.ibm.ws.webcontainer.srt.SRTServletResponseContext.sendError(SRTServletResponseContext.java:152)
at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendError(SRTServletResponse.java:626)
at com.ibm.annap.test.TestServlet.doPost(TestServlet.java:35)
at com.ibm.annap.test.TestServlet.doGet(TestServlet.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:431)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
Thanks
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic