wood burning stoves 2.0*
The moose likes Servlets and the fly likes Servlet filter exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet filter exception handling" Watch "Servlet filter exception handling" New topic
Author

Servlet filter exception handling

Jefferson Parke
Greenhorn

Joined: May 03, 2004
Posts: 5
Is there any recommended approach to catching exceptions thrown by servlet filters, in the literal sense, not just an error-page forward? Specifically, I am using the jCIFS NTLM authentication filter (http://jcifs.samba.org/src/docs/ntlmhttpauth.html) and want to catch exceptions such as java.net.UnknownHostException thrown when one of the filters' arguments is invalid. I want to catch exceptions thrown by servlet filters, log them, and then forward to an appropriate error page. Any recommendations?
Thanks,
Jeff
danny liu
Ranch Hand

Joined: Jan 22, 2004
Posts: 185
Just use Log4j from apache.
Dan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

You can declare an error handler for any particular exception in the web.xml file.
(Log4j can in no way help catch the exception and forward).
[ May 03, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jefferson Parke
Greenhorn

Joined: May 03, 2004
Posts: 5
When you say error handler, are you referring to the error-page web.xml definition? If so, this is not quite what I am looking for. Error-page simply forwards the request to some URL but doesn't forward the exception with it (or does it?). I need the ability to log the exception first then forward to some URL. What were you referring to?
Thanks,
Jeff
Jefferson Parke
Greenhorn

Joined: May 03, 2004
Posts: 5
I see that attributes with keys that start with "javax.servlet.error" are forwarded in the request object to the target of the <error-page>. I'll just use the information provided by those attributes to create a log entry. Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

I see that attributes with keys that start with "javax.servlet.error" are forwarded in the request object to the target of the <error-page>

Exactly. Any info you need to process the error is available.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet filter exception handling
 
Similar Threads
Filters & Dispatchers
Filter being called for Struts' forwarded JSP
Filter questions
issue realted to IllegalStateException
A forward in a include page?