This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes response.sendError & error-page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "response.sendError & error-page" Watch "response.sendError & error-page" New topic
Author

response.sendError & error-page

Andriy Fedotov
Ranch Hand

Joined: Mar 07, 2008
Posts: 49
I have a problem with catching error page

When I throw an Throwable exception everything works fine (my error-page, defined in the DD catches it)

but if do response.sendError(404) in my servlet code my error-page doesn't catches it..

here's the source:

DD:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/jsp/ch11/Error.jsp</location>
</error-page>

<error-page>
<exception-type>404</exception-type>
<location>/jsp/ch11/Error.jsp</location>
</error-page>

Servlet's doGet method (that invokes the error)

//throw new IOException("asd "); //works OK, Error.jsp catches it
response.sendError(404); // see HTTP Status 404, not my Error.jsp

Thank you for your time
Andriy Fedotov
Ranch Hand

Joined: Mar 07, 2008
Posts: 49
sorry guys, i found out what was the problem.

for http errors like 404 i should have used <error-code> in the <error-page>

so,

<error-page>
<error-code>404</error-code>
<location>/jsp/ch11/Error.jsp</location>
</error-page>

works well
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: response.sendError & error-page
 
Similar Threads
error-page
Jsp error page handling
error page under WEB-INF
tomcat 5 and error page
tomcat 5 and error page