• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

page not redirecting to specific mapped exception type

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply folks!

Anyways im actually preparing for 1Z0 899
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic