jQuery in Action, 2nd edition*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes setHeader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "setHeader" Watch "setHeader" New topic
Author

setHeader

deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124
We are setting the response Header.But the getHeader method is in the HttpServletRequest Object.

How to get the Header Value (which has been set using response.setHeader method )
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
Request and response (and their headers) have nothing to do with one another; it makes no sense to retrieve response headers (or set request headers) on the server. That's for the client (the browser) to do.
[ August 20, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Ok then we add the info in to response and read the info from the request the reason for this is. when the first request comes and say i call request.getSession() it attaches the session id in the response header even though session id is attached in the response we still call request.getSession() rather than response.getSession(); this is mainly because first request comes and once processed next request will not have any info about the first request. Ok fine in that case the first response was sent and for second request it will send second response which will also not have any info about the previous response is that correct? if correct then how this thing is working. Is it some thing like that server will maintain some state for every client that when you call response to perform add or set it will write in to this place and when we call request to retrive the info it will use some mechanism to identify which is the location where it has wrote the info and get that info for the request. in this way just by having mechanism of identifying the request and responses and corressponding location where it is storing the info it will process the request. Is this Correct?

Thanks
[ August 21, 2008: Message edited by: raja ram ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
raja ram,

by not using punctuation you're making it very hard to understand your post. Please go back and edit your post accordingly.
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
Hi,

Any updates on this?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42632
    
  65
Sessions are independent of individual requests and responses. They are identified by a session ID, which is set as a cookie by the first response after the session has been created. Each request coming in after that will include the session cookie. Thus, although the session state is kept on the server, the crucial information for associating a session to a request is done through the cookie (which is sent with each request).

(There's also another mechanism for transporting the session ID -called URL rewriting- for cases where cookies are not available.)
deepa raj
Ranch Hand

Joined: Jul 25, 2008
Posts: 124
when the first request comes and say i call request.getSession() it attaches the session id in the response header even though session id is attached in the response we still call request.getSession() rather than response.getSession();


When you call the getSession() , server will create the session-id cookie and attaches that cookie to the response header.

After that , if the clent wants to continue the session , it should get the session-id cookie from the response header , it has to attach the same session-id to the Request Header.

So on the hole, Response header are being set for the clients like browser.
Request Headers are from the client set by the client for Server to process the request.

[ UD: replaced CODE tags with QUOTE tags so that the layout isn't broken ]
[ August 22, 2008: Message edited by: Ulf Dittmer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setHeader