• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Page

 
Chatura Dilan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please post the code to analyze the problem.



Thanks and Regards
Joy
 
Chatura Dilan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Joy here is the code

My DD




index.jsp



arException.jsp




tException.jsp

 
Gunnar Maluf
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joy Mukherjee
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add
errorPage="true" to both the JSP and test the results.


Thanks and Regards
Joy
 
Chatura Dilan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"MyMyselfAndI", please check your private messages for an important administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic