Hi all- I�m writing a servlet filter to redirect various URLs in our applications. It works in conjunction with an Authentication Filter. 1)The Authentication Filter puts authentication parms into the request header for apps to use (using req.setAttribute). 2)The Redirect Filter intercepts various pages, checks the authentication parms, and may redirect to an appropriate page (usually a start page). The part I�m having problems with is that the redirect filter must a) set more parms in the request header (using req.setAttribute) and b) set a cookie before it redirects. This is not being done, I suspect, because the redirect (response.sendRedirect) is ignoring them. I have to use response.redirect as the redirected URL can be on another server. Can I do this? Redirect AND set parms + cookie as well? I�m using WAS 5.1. Thanks, Max Tomlinson
Author and all-around good cowpoke
Joined: Mar 22, 2000
One option that has been discussed here before is to have your servlet make the connection to the other server, using request variables your servlet creates - in effect, your servlet creates a client for the other service and relays the output of the other service to your real client. This gets pretty complicated for all but the simplest responses. Bill
The key with response.sendRedirect is that the browser will make a "brand new request" for the resource you are redirecting to. In that way, you loose all attributes that you set on the 'previous' request.
One option is to use request parameters instead. You could do something like:
As a side note... setting a cookie with response.sendRedirect seems to work, I just tried it the other day and it works. Tomcat 4.1.29, IE 6, Mozilla.
I suspect that browsers are capable of acting appropriately to both a cookie in the header, and a 300-type "find that page over here" header.
Joined: Jul 17, 2001
Mike, Bill- Thanks for the replies: Mike: So setting a cookie in the header DOES work for IE 6? I'll have to double-check...I didn't see where that was happening. thanks again Max
To get IE to slow down and show you cookies: Tools | Internet Options | Privacy tab | Advanced button Check the 'override' box and select 'prompt' for first-party cookies. And make sure the 'accept session cookies' is unchecked.
I'm able to see both my jsessionid cookie and my other manually set cookie being set, and then the redirect occurs. The cookie is still good after this.