Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

issue with error jsp

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Creator of Enthuware JWS+ V6
Posts: 3348
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3348
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3348
303
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic