• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Example of setting headers

 
chandan kumar mitwaa
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone quote me a good example of how to use headers.

Suppose that i have set a header to response. Now how am i going to use that say for eg in a forwarded page.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chandan kumar mitwaa wrote:Suppose that i have set a header to response. Now how am i going to use that say for eg in a forwarded page.

With request forwarding, response buffer will be cleared before the target servlet's service method executes.
 
chandan kumar mitwaa
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Vijitha Kumara


I just needed a general example where i set a header of my own and that i could be able to use somewhere....
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your code sets a header that you define yourself (in other words, not a header used by HTTP, like Content-Type, Content-Encoding, Content-Length, Expires etc.) then you need a client that can make sense of it. That could be a JavaScript AJAX call, or Java code that uses the URLConnection class to access the server; both provide access to the response headers, so the client code could do something based on those.
 
Sony Agrawal
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i access the header's value from the response object?
Like.... response.getContentType(), aren't there any method to get other headers? OR Aren't these header's value not retrieved usually ?
Or send the response status code to the user(to display in as html) ??
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets *set* the response headers, so it doesn't generally make sense for them to *read* those headers.

Request headers are set by the client (usually the browser, or a JavaScript XMLHttpRequest object, or a Java URLConnection object) and then sent to the server; response headers are set by the server and then read by the client.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic