File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 41106
    
  45
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: 41106
    
  45
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: 41106
    
  45
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: addHeader() and setHeader() not working
 
Similar Threads
user authentication and dao
HTTP status 500-
HttpServletRequest.getHeaders(aString)
Getting browser language settings
sending email in servlet