Hey people, This is the scenario.. I need to send a custom value in the header of my request alongwith the normal request headers and then retrive it in the destination servlet. For eg, I want to send the user name in the header of the request, whether it is from a servlet or from a JSP, and then retrieve the value in the servlet that processes the information. If it is a servlet to servlet communication, can the response headers be used to set and retrieve the value....? Someone plzzzzz advice in this regard and it is a bit urgent. Thanks in advance for the help. You can mail me at email@example.com if you come up with anything plz.
Dept of Electrical and Comp Engg
University of Massachusetts, Amherst
What request is this that you want to attach headers to? Were you hoping that by attaching a header to your response, the client (browser) would kindly copy it over to the next request it sends to your host? That isn't going to work. You say
I want to send the user name in the header of the request, whether it is from a servlet or from a JSP
but that doesn't make much sense, because servlets and JSPs don't send requests. They send responses to requests.
=> are you talking: 1) of a servlet forwarding a request to another servlet or JSP before reponding to the client? 2) of a servlet processing a request, saving some info about it, sending a response to the browser and expecting to get the info back when getting another request from the save client?
In the first case, you would rather put your info in an attribute of the ServletRequest and not in a a parameter. This info disapears as soon as the response is sent to the client. Have a look at ServletRequest.setAttribute(String, Object).
If you want to keep some info during several requests of the client, you wan to put the attribute in the HttpSession. Have a look at ServletRequest.getSession() as well as at this encoreURL thing.
It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
As application developers, we shouldn't really have to. The headers are for manipulating aspects of the HTTP protocol.
Some cases where an application developer might find him/herself writing headers would be servlet/applet communication. You would, of course, need to understand HTTP headers if you were to write your own web client.
I built a component for an application that served up some server side dynamic CSS. By working with the If-Modified-Since and Date headers I was able to get the browser to use it's cached version of the CSS sheet when there were no changes. This cut down on a lot of bandwith usage.
I would be very hesitant to start adding my own headers just to pass information back and forth between server side components. That's what querystring and post parameters are for.