Julia Julia

Greenhorn
+ Follow
since Dec 07, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Julia Julia

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 ?