Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Error Page Filter

 
Michael J. Makunas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Michael J. Makunas
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except for the wild-carding. I usually handle the most common 500, 404, and 403 error codes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic