This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes QUESTION on ERROR HANDLING Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "QUESTION on ERROR HANDLING" Watch "QUESTION on ERROR HANDLING" New topic
Author

QUESTION on ERROR HANDLING

Julia Julia
Greenhorn

Joined: Dec 07, 2004
Posts: 1
Hi ,

I was reading the Manning's SCWCD Study Kit , and particularly confused on the NOTE regarding error handling on page 103 :

"if an error handler is invoked as a result of either the setStatus() or the sendError() method, javax.servlet.error.exception and javax.servlet.error.exception_type are set to null. Similarly, if an error handler is invoked as a result of an exception, javax.servlet.error.code is set to null"

However,

when I wrote a test program that throws an exception , I was able to retrieve BOTH error code and exception type. Here's the output :

ERROR CODE : 500 EXCEPTION TYPE : class java.sql.SQLException

and here's my code :

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

PrintWriter pw = resp.getWriter();
pw.print("Print something first ");

throw new ServletException("SQLException inside",new SQLException());
}

here's my JSP error page :

<BODY>
I AM THE INTERNAL SERVER ERROR PAGE

THE EXCEPTION THAT I RECEIVE WAS:

ERROR CODE :
<%= request.getAttribute("javax.servlet.error.status_code") %>


EXCEPTION TYPE :

<%= request.getAttribute("javax.servlet.error.exception_type") %>

</BODY>

here's the mapping :

<error-page>
<error-code>500</error-code>
<location>/Error1JSP.jsp</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/Error1JSP.jsp</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/Error1JSP.jsp</location>
</error-page>


Can someone clarify or correct ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QUESTION on ERROR HANDLING
 
Similar Threads
Why the exception in my error page is null when error comes from a servlet?
Trouble with Error Pages
Not recognizing the error-page tag in web.xml
servlet as error-page
Q: Appropriate Exception Handling in a servlet