aspose file tools*
The moose likes Servlets and the fly likes servlet filter sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet filter sendRedirect" Watch "servlet filter sendRedirect" New topic
Author

servlet filter sendRedirect

Mark Manns
Greenhorn

Joined: Jul 06, 2006
Posts: 14
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

Joined: Jan 10, 2002
Posts: 60077
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Manns
Greenhorn

Joined: Jul 06, 2006
Posts: 14
A forward does the same thing --- invokes the servlet filter.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

No, the filter will not be invoked on the forward.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jan 24, 2005
Posts: 489



By default filters are applied for request only.

ram.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

Originally posted by Benjamin Leonard:
I think the default behaviour is the the filter is not trigger on a forward


That is correct.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet filter sendRedirect
 
Similar Threads
Send Redirect
Is there anyboby has used the Filter?
Deploy JSF Problem
call to sendRedirect() and getSession() after forward() throws IllegalStateException
Peculiar problem with js and css file