This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes set header and getheader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "set header and getheader" Watch "set header and getheader" New topic
Author

set header and getheader

Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
I am trying to print the value of a header and getting a null value as the output. Any ideas?

code:

resp.setHeader("foo","baris");
String hvalue = req.getHeader("foo");
out.println("<br>foo value is"+ hvalue);

output:

foo value isnull


SCJP 1.4 | SCWCD 1.4 | SCJD (WIP)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Are you doing this in the same servlet ??


[My Blog]
All roads lead to JavaRanch
Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
yes
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You are setting the header to the response. Ok.
You are reading the request header. Ok.
But the request header and the response header are different.
Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
Thanks Satou.

I got it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: set header and getheader
 
Similar Threads
Display of hashmap values using jstl
Stringbuffer remains unchanged in a method
Passing variable into methods
Question about servlet filters
Use of .setHeader() and .addHeader() methods