This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes addHeader() and setHeader() not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "addHeader() and setHeader() not working" Watch "addHeader() and setHeader() not working" New topic
Author

addHeader() and setHeader() not working

Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Hi,

I am preparing for OCPJWCD. I am a little stuck on addHeader and setHeader methods. I do understand the difference, but when i am trying to implement it in the code and retrieving the values either via getHeaders() or getHeader(). It is showing value as null. I am adding the code here. Can someone check and let me know, what exactly is going wrong.



What am i exactly doing wrong? Any pointers would be helpful.
Thanks,
Ben


Twitter:ben_pheonix
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42359
    
  64
You're confusing request headers (which are sent from the client to the server) and response headers (which are sent from the server back to the client). While both are HTTP headers, there's otherwise no relationship between them.


Ping & DNS - my free Android networking tools app
Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Dear Ulf,

Thanks a ton. I got the understanding of what you are trying to tell. I have a question, i am setting headers in the response, in order to see these headers
and retrieve them. What can be done? Can i dispatch the request to another servlet and take out headers from the request? Please clarify.

Thanks,
Ben
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42359
    
  64
No. As I said, response headers are not request headers. You can see them in the client that receives the response, whatever that happens to be (possibly a web browser).
Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Dear Ulf,

Thanks a ton. I got the explanation right burnt in the head. Thanks a ton again.

Thanks,
Ben
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42359
    
  64
A tool like the LiveHTTPHeaders extension for Firefox will show what headers are sent as part of the request, and what comes back as part of the response. That can be very useful for debugging web apps (or for understanding HTTP).
Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Dear ulf,

Thanks so much for a wonderful feedback. I will use this extension and update you with my experience.

Ben
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: addHeader() and setHeader() not working