• Post Reply Bookmark Topic Watch Topic
  • New Topic

page not redirecting to specific mapped exception type

 
Ernesto Hilvano
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Day,

My code below does not redirect to specific exception declared on DD ( expected exception is Arithmetic Exception )

Sample.jsp


web.xml



when i am getting an arithmetic exception, it always redirect to ErrorPage.jsp instead of ArException.JSP!

help!
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is happening here is that Tomcat has wrapped exceptions that happen on a JSP page in its own custom Exception (org.apache.jasper.JasperException in JspServletWrapper.handleJspException)
As such it doesn't match "ArithmeticException" in the web.xml, but does match the Throwable.

I don't know of any way to work around this except to not throw exceptions from JSP pages.

For the most part you shouldn't be including scriptlet code/expressions in a JSP.
If you follow that convention, it would be a rare case that an exception would occur in this manner.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:For the most part you shouldn't be including scriptlet code/expressions in a JSP.
If you follow that convention, it would be a rare case that an exception would occur in this manner.

He's not -- that's an EL expression.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point.
I got mixed up because I found a very similar question on the internet
And then I tested with ${ 1/0 } (gives an answer of "Infinity") as opposed to ${1 % 0}

I think the diagnosis remains the same though. Tomcat wraps the exception in a JasperException which results in the Throwable being matched instead of the ArithmeticException
However some more research sent me to here
Which quoted the Servlet Specification 9.9.2

If no error-page declaration containing an exception-type fits using the class-hierarchy match, and the exception thrown is a ServletException or subclass thereof, the container extracts the wrapped exception, as defined by the ServletException.getRootCause method. A second pass is made over the error page declarations, again attempting the match against the error page declarations, but using the wrapped exception instead.


In other words, it starts off with the JasperException, which matches against the Throwable declared in your web.xml and you get ErrorPage.jsp.
If you REMOVE the exception-type for throwable, then JasperException doesn't get matched. Because it is a JSP Exception, it unwraps, finds the root cause and voila! ArException.jsp here we come.




 
Ernesto Hilvano
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply folks!

Anyways im actually preparing for 1Z0 899
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!