aspose file tools*
The moose likes Servlets and the fly likes servlet filters and request headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet filters and request headers" Watch "servlet filters and request headers" New topic
Author

servlet filters and request headers

Srivatsan Varadarajan
Greenhorn

Joined: Jul 07, 2006
Posts: 4
I am using a filter to check the login access to my application. Before It comes to the filter, the user -id is already set in the request header as one of the attributes. But, by the time , it gets to the filter, I lose that header. The reason why I say that I am losing the header name is this: I took the logic and put that in my action class and print out the header and it totally works. Should it be the same request that gets passed either way? I would really appreciate somebody's help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

"sri_varada",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
by the time , it gets to the filter, I lose that header

Requests go through all parts of the filter chain BEFORE they get to the servlet so that sounds rather odd.

Exactly how and where are you setting this user id header?

How many filters do you have?

Bill
Srivatsan Varadarajan
Greenhorn

Joined: Jul 07, 2006
Posts: 4
Thanks Bill for replying during the weekend. There is first an application url that the users go to and this goes through our LDAP server where the user-id is verified and we have a request header called "user" set there. So, what essentially we are trying to do in our filter is to check for the presence of that request header, "user". For some reason, when we print out all the request header name and value, that "user" request header is not among them. But I know for sure that the request header , "user" is set because I took the same code that I wrote in filter and put it in the struts action class and print out all the names and values, it is present. So, I don't understand why the filter and the action class are getting totally two different request objects. I have only one filter that checks for that "user" request header. Please let me know if I can provide any more details. I really appreciate your help.
abhijit Ohal
Ranch Hand

Joined: Mar 10, 2006
Posts: 64
IF you are using struct for developing webApplication then in struts-config.xml for your login action make redirect property false.

OR IF you are using servlet for developing webApplication use forward instead of response.sendRedirect().

eg.
<code>
<action path="/ResetPassword"
type="ResetPasswordAction"
name="ResetPasswordForm"
scope="session" >
forward name="login" path="/Camp.jsp" redirect="false"/>
</action>
</code>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12789
    
    5
I bet that Abhijit Ohal identified the problem! When a request is redirected, the client creates a NEW request so your added header vanishes.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet filters and request headers