wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes issue with error jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "issue with error jsp" Watch "issue with error jsp" New topic
Author

issue with error jsp

Amitosh Mishra
Ranch Hand

Joined: Feb 11, 2010
Posts: 49
Hi all,

i have configured a filter in my web.xml to test the exception scenario occurring in filter



in dofilter() method i am simply throwing a null pointer exception




please let me know whether any uncaught exception from the filter will be caught error page configured.

while running this in IE i am getting HTTP 404 not found.
in FF blank page is coming.

thanks
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

Hi Amitosh,

please let me know whether any uncaught exception from the filter will be caught error page configured.

Not like this, but it is possible if you change the filter definition:


Regards,
Frits
Amitosh Mishra
Ranch Hand

Joined: Feb 11, 2010
Posts: 49
Hi Frits..
it is working properly now..
the path of errorj.sp need to be like <location>/WEB-INF/error.jsp</location>
after the changes it is working properly.

thanks..
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

just to correct the web.xml entry: the <dispatcher>ERROR</dispatcher> element should actually be inside the <filter-mapping> and not in the <filter> element.

Like this:

I am surprised that it also works when put in the <filter> element. Probably something tomcat allows (not following the specs to the full extend)
Just check the Servlet 2.4 specs, chapter SRV.13.4 Deployment Descriptor Diagram, page 138 (8. filter-mapping Element)

Regards,
Frits
Damien Clarke
Greenhorn

Joined: Mar 10, 2010
Posts: 6
Frits - Is the <dispatcher> element really needed here? The exception is thrown from within the filter so the filter will have been invoked already through the <url-pattern>/*</url-pattern> mapping element. He's not trying to invoke the filter on exception being thrown. I think the problem, as Amitosh said, was just with the incorrect path to the error page.

Is this correct?(just want to make sure my own understanding is correct)
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1665
    
  25

Hi Damien,

You are correct!

I thought that exceptions in filters are not handled by the error-page mechanism, but in fact they are (Servlet 2.4 specs)

SRV.9.9.2 Error Pages
A servlet or filter may throw the following exceptions during processing of a request:
- runtime exceptions or errors
- ServletExceptions or subclasses thereof
- IOExceptions or subclasses thereof
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.


I tried to figure out what the meaning of the <dispatcher>ERROR</dispatcher> in a <filter-mapping> is, and this is what I found:

SRV.9.9.3 Error Filters
The mechanism described in Section SRV.6.2.5, "Filters and the RequestDispatcher" may be used to specify
filters that are applied before an error response is generated.

This looks like you can let a filter be invoked upon an error before the error-page mechanism starts working. However I couldn't get an example working on my Tomcat 5.5 server.

Regards,
Frits
Damien Clarke
Greenhorn

Joined: Mar 10, 2010
Posts: 6
Thanks Frits,

As I say - just wanted to make sure I had understood it myself.

For info - from the Servlet 3.0 spec (Section 6.2.5):
By using the new <dispatcher> element in the deployment descriptor, the
developer can indicate for a filter-mapping whether he would like the filter to be
applied to requests when:
.
.
The request is being processed with the error page mechanism specified in ”Error
Handling” on page 102 to an error resource matching the <url-pattern>.
This is indicated by a <dispatcher> element with the value ERROR.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: issue with error jsp