• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

addHeader,setHeader

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I am not able to create a simple new header in my response (
can we do this in a getPost()?



But I am getting null for 's' .How should I add a new header?

Moreover I also tried to setHeader("CONTENT-LENGTH","1024");
and then tried to display the value for this header,but it did not show me the updated value.Why did not my setHeader method work? Why dint it replace the existing value?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request and response objects obtained within the doGet/doPost methods are unrelated to one another. Any header set in the response will be available to the client to which it is sent - for web apps that is generally a browser. (In Firefox, you can see all headers using the "Tools -> Get Info" menu.)
 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This did not clarify my query? why am I not able to add this header?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You ARE able to add/set headers. But the response object has no methods for getting the headers that have been set, and the request object (which you're trying to use) has no relationship to the response object. So there's no way for you to check which headers haven been set in a response within the servlet container. The way to access response headers is to do it in the client to which the response is sent, like I mentioned about Firefox.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic