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

Servlet - Servlet Communication - Setting the headers

Abhishek Dwaraki
Ranch Hand

Joined: Feb 13, 2006
Posts: 44
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 abhishek.dwaraki@gmail.com if you come up with anything plz.


Regards,
Abhishek Dwaraki
Dept of Electrical and Comp Engg
University of Massachusetts, Amherst
Manuel Palacio
Ranch Hand

Joined: Oct 16, 2000
Posts: 45
Can't you just append the value as a request parameter?

like: myapp/whatever.html?userName=ziggy

/M
[ April 07, 2006: Message edited by: Manuel Palacio ]

<a href="http://www.newinstance.net" target="_blank" rel="nofollow">http://www.newinstance.net</a>
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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.
Ganesh Chinni
Greenhorn

Joined: Dec 30, 2005
Posts: 24
Can you explain why do you want to put user name in the headder and send it, when there are other ways to send the parameter.

Putting username in headder is not a good idea.
siva prakash
Ranch Hand

Joined: Aug 24, 2004
Posts: 80
Hi,

In which senarios we put data in response header?



Thanks
Prakash
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
If it is a servlet to servlet communication


=> 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.


Cheers


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by siva prakash:
Hi,

In which senarios we put data in response header?



Thanks
Prakash


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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet - Servlet Communication - Setting the headers