aspose file tools*
The moose likes Servlets and the fly likes Custom Error Page Filter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Custom Error Page Filter" Watch "Custom Error Page Filter" New topic
Author

Custom Error Page Filter

Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
Hi all-

I'm trying to write a servlet filter that displays custom error pages. (Yes, I do know the standard way of specifying error pages in web.xml but the template of the error page needs to vary and I'd rather not put that logic in a jsp.) I'm doing all the normal wrapping of the response, etc. in order to be able to modify the response, but no matter what I do it just seams to ignore anything written to the output stream. I seem to remember someone telling me once that you cannot modify the response when the status is an error. Is this the case or am I doing something else wrong?
[ August 14, 2008: Message edited by: Michael J. Makunas ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

I still don't get the filter. Why not just declare a controller servlet as the error handler in the deployment descriptor and handle any decision making there?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael J. Makunas
Ranch Hand

Joined: Mar 11, 2002
Posts: 37
Originally posted by Bear Bibeault:
I still don't get the filter. Why not just declare a controller servlet as the error handler in the deployment descriptor and handle any decision making there?


Good point. I thought of something like that after I just posted this. But my concern is that I need/want:

1. To know what the originally requested URL was.
2. To know what the original status code was.
3. To minimize what I have to add to web.xml. In other words can I do something like:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

Except for the wild-carding. I usually handle the most common 500, 404, and 403 error codes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Error Page Filter