aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Error Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Error Page" Watch "Error Page" New topic
Author

Error Page

Chatura Dilan
Ranch Hand

Joined: Feb 13, 2007
Posts: 44
In DD
<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/arException.jsp</location>
</error-page>


<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/tException.jsp</location>
</error-page>

What happen my jsp page throws an ArithmeticException
I tried it, but it show me tException page, but according to the mock question it should be arException.jsp. I don't know why is that?


-----------------------------------<br />If at first you don't succeed, try again without cry. Everytime You will learn what not to do next time, untill you succeed.<br /> <br />SCJP 1.4 (78%)<br />SCWCD 5 (95%)<br />BICT - UCSC
Joy Mukherjee
Ranch Hand

Joined: Aug 10, 2008
Posts: 62
Can you please post the code to analyze the problem.



Thanks and Regards
Joy


B.Tech (E.E),IIT Kharagpur<br />SCJP 5.0<br />SCWCD 5.0<br />PMP
Chatura Dilan
Ranch Hand

Joined: Feb 13, 2007
Posts: 44
hello Joy here is the code

My DD




index.jsp



arException.jsp




tException.jsp

Gunnar Maluf
Ranch Hand

Joined: Dec 29, 2007
Posts: 39
Originally posted by Chatura Dilan:
hello Joy here is the code

My DD




index.jsp



arException.jsp




tException.jsp



The book says: Declaring a catch-all error page
This applies to everything in your web app´┐Żnot just JSPs. You can override it in individual JSPs by adding a page directive with an errorPage attribute.

If you override it, it works.


Sun Certified Associate for Java Platform
Sun Certified Java Programmer 5.0
Sun Certified Web Component Developer 5.0
Joy Mukherjee
Ranch Hand

Joined: Aug 10, 2008
Posts: 62
Add
errorPage="true" to both the JSP and test the results.


Thanks and Regards
Joy
Chatura Dilan
Ranch Hand

Joined: Feb 13, 2007
Posts: 44
I added <%@ page isErrorPage="true" %> to both exception pages, but i get the same results, i don't know why? anyone have this issue? anyway what do we select if we get this kind of question in the exam?
Gunnar Maluf
Ranch Hand

Joined: Dec 29, 2007
Posts: 39
Originally posted by Chatura Dilan:
I added <%@ page isErrorPage="true" %> to both exception pages, but i get the same results, i don't know why? anyone have this issue? anyway what do we select if we get this kind of question in the exam?


This is wrong. You have to add <%@ page errorPage="arException.jsp" %> in the
index.jsp

regards
Gunnar
Joseph Muller
Greenhorn

Joined: Aug 24, 2008
Posts: 7
I think the problem is in Tomcat.
In Servlet 2.4 spec you can find:

The Web application may have declared error pages using the exception type element. In this case the container matches the exception type by comparing the exception thrown with the list of error-page definitions that use the exception-type element. A match results in the container returning the resource indicated in the location entry. The closest match in the class hierarchy wins. (page 74)

You may do some test
1. Create index.jsp page:

<html>
<body>
<h1>Hello World</h1>
<% if(true) {throw new java.io.FileNotFoundException(); }%>
</body>
</html>
2. Next create web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<!--
-->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/Throwable.jsp</location>
</error-page>
<!--
-->
<error-page>
<exception-type>java.io.IOException</exception-type>
<location>/IOException.jsp</location>
</error-page>
<!--
-->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/Exception.jsp</location>
</error-page>
<!--
-->
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/FileNotFoundException.jsp</location>
</error-page>
</web-app>

3. Create also pages witch are in locations tags for example Throwable.jsp
<%@ page isErrorPage="true"%>
<html>
<body>
<h1>Throwable</h1>
<h4><%= exception %></h4>
</body>
</html>
4. Run this app in Tomcat and for example in GlassFish

You can comment some declarations of error-page and observe result. GlasFish every time choose the closest exception type for thrower exception, but Tomcat have problem when you declare error-page for exception-type Throwable and Exception. If you haven't it all is also correct.

Regards,
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

"MyMyselfAndI", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error Page