redirect my incoming requests to an absolute URL from a Servlet Filter.
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rabih_Yazbeck
Posted On:   Thursday, February 27, 2003 06:23 AM

Hello, I have problem in trying to redirect my incoming requests to an absolute URL from a Servlet Filter. I have this filer: secureconnectionfilter cart.security.filter.SecureConnectionFilter secureconnectionfilter securitytest I cannot use the request dispatcher because it forwards to a relative address in the same servlet context only: RequestDispatcher rd = context.getRequestDispatcher("/index.jsp"); rd.forward(request, response); so I want to use sendRedirect, like: HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.sendRedirec   More>>

Hello,

I have problem in trying to redirect my incoming requests to an absolute URL from a Servlet Filter.

I have this filer:

			

secureconnectionfilter
cart.security.filter.SecureConnectionFilter


secureconnectionfilter
securitytest




I cannot use the request dispatcher because it forwards to a relative address in the same servlet context only:

			
RequestDispatcher rd = context.getRequestDispatcher("/index.jsp");
rd.forward(request, response);



so I want to use sendRedirect, like:

			
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.sendRedirect(httpResponse.encodeRedirectURL("http://localhost:8080/cart/index.jsp"));



But it is not working, it ignores the sendRedirect without throwing any exception! so how can I redirect to a new page from Filter outside the servlet context?




Any idea? Thank you in advance..



- Rabih    <<Less

Re: redirect my incoming requests to an absolute URL from a Servlet Filter.

Posted By:   AlessandroA_Garbagnati  
Posted On:   Thursday, February 27, 2003 09:53 AM

Hi,

I have tried your code and It does throw an exception. Probably you are not catching it, or you are catching it and ignoring.


I have tried this:


...
try {
HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect(res.encodeRedirectURL("http://www.yahoo.com/"));
...
}
catch(Exception e) {
filterConfig.getServletContext().log(e.getMessage());
}
...

And I got an IllegalStateException


To fix the problem, I have simply put a return; after the sendRedirect call.

Re: redirect my incoming requests to an absolute URL from a Servlet Filter.

Posted By:   rajeev_kumar  
Posted On:   Thursday, February 27, 2003 08:03 AM

Dispactcher should have servlet context as input parameter

try thid

context.getRequestDispacher("/cart/index.jsp")
About | Sitemap | Contact