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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date