Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java Servlets
Expertise: Beginner
Dec 5, 2000

Updating HTTP Headers

Question:
In the first servlet we set the value for HTTP header as below:
response.setHeader("SessionKey","SessionValue");

In the next servlet we tried retrieving the above set header value as:
request.getHeader("SessionKey");

We are getting null as output of getHeader. How can we get the HTTP header set in first servlet, in second servlet?

Answer:
I assume from your question that you are doing some kind of request forwarding from one servlet to another. If this is the case, the mistake you are making is to set the header in the response. The response variable is an instance of "HttpServletResponse," which is used to return a result back to the client accessing the servlet. Any headers you set in the reponse will be sent to the client, not to a chained servlet.

If you want to add headers to a forwarded request,set them in the request variable before passing it on to the next servlet in the chain.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap