• Post Reply Bookmark Topic Watch Topic
  • New Topic

Response Headers

 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are response headers for
eg. the content-Type, that is being sent back to the client.

Was wondering why there is no getHeaders() on response, though it contains response Headers?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apparently the definers of the servlet API deemed that reading response headers back once you
have set them is not useful.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, to add to the question, HttpServletRequest doesnt have addHeader() whereas HttpServletResponse has....

m not really very clear of the purpose of headers...(i will be gr8, if you can provide some info)
i do get the use of some.. like 'accept-language', in that case shouldnt there be addHeader, to accept more languages???
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same reasoning: the request headers are meant to provide information for processing the request on the server. There's no point in adding more headers once the request has arrived at the server.
If you need to attach information to it, you can use setAttribute.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, why there is a addHeader for HttpServletResponse
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because -for the reponse- the server sets the headers, whereas -for the request- the client does.

Since you mention "accept-language", that's something the browser sets, and which is based on the language settings in your browser. No matter how many languages are accepted, they're all set in just a single header. If you have a local Tomcat running, and the examples installed, you can check how that works by going to http://localhost:8080/servlets-examples/servlet/RequestHeaderExample.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition:
Why would you want to add languages to that header from the server?
That header is information about what the browser can handle.
Adding headers from the server would only make that information inaccurate.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This still does not answer the question...

why there is a addHeader for HttpServletResponse

the server sets headers to the client to see what it is sending (response headers)and the client sends the headers to say what all it accepts(request headers).

In this case there should not be addHeader() in the request or response
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by geetu lalchandani:
This still does not answer the question...

why there is a addHeader for HttpServletResponse

the server sets headers to the client to see what it is sending (response headers)and the client sends the headers to say what all it accepts(request headers).

In this case there should not be addHeader() in the request or response




Request reads headers sent from the browser.
Response sends headers from the server to the browser.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
understood....


Request reads headers sent from the browser.
Response sends headers from the server to the browser.


but then , when will we need to add additional headers???
why is there a addHeader in response?? why will the server add additional headers, if the client (browser) doesnt accept those.. as it said... in the request headers, it accepts only those it specified...
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server can set as many response headers as it wants to and needs to, using the addHeaders method. There is no question of the client accepting headers - the headers are there, and if the client doesn't know what to do with them, it can simply ignore them.

I think you may be getting confused by the "accept-language" header, which is a request header. It specifies which languages the client wishes to be served, and has nothing to do with which headers are sent. Besides, it is only one of several headers that are used; check the Tomcat example I mentioned before - it shows other request headers that are used.

If you want to have a look at request and response headers in action, you can use the LiveHTTPHeaders extension for the FireFox browser - it shows both kinds of headers as they are sent and received by the browser.
[ November 30, 2005: Message edited by: Ulf Dittmer ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There can be multiple values for a particular header type. And that's why there is a addHeader method in addition to the setHeader method. addHeader adds to the header that's already set for the particular type, if any. While setHeader replaces it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!