• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet filter sendRedirect

 
Mark Manns
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have a servlet filter with a try/catch. In the exception catch I use a sendRedirect to my error.jsp. But that doesn't work --- the sendRedirect invokes the filter again --- and that fails again --- and that sends another redirect .... and on and on and on.

I know I can use response.sendError(..) but that doesn't give me my pretty error page.

Any ideas anyone?

Thanks

Mark
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you redirect, you initiate a new request, which of course re-invokes the filter.

Rather, why do you not forward to the error page?
[ July 06, 2006: Message edited by: Bear Bibeault ]
 
Mark Manns
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A forward does the same thing --- invokes the servlet filter.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add logic to your filter that checks the URL to see if the request is bound for your error page, if so, let it through, if not, invoke your filter code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the filter will not be invoked on the forward.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to let you know :
in a recent servlet specification( if i remember well 2.4) there is a way to configure your filter to be trigger on a forward or not (this is done in the web.xml file). I think the default behaviour is the the filter is not trigger on a forward !


another possibility is to configure your filter mapping in a way that it will not be triggered for error.jsp file.

i hope this will help you !
[ July 07, 2006: Message edited by: Benjamin Leonard ]
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


By default filters are applied for request only.

ram.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64717
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Benjamin Leonard:
I think the default behaviour is the the filter is not trigger on a forward


That is correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic