Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

problem adding response headers in servlet

Posted on 2006-10-19
1
Medium Priority
?
477 Views
Last Modified: 2013-12-10
I am adding values to a response header in a servlet:
   response.addHeader("detail 1:", "something");
   response.addHeader("detail 2:", "something else");

I then redirect to another servlet to see if the response headers were actually added:
   response.sendRedirect("servlet2");

in servlet2 I enumerate and print the headers:

   Enumeration e = request.getHeaderNames();
   while (e.hasMoreElements()) {
      String name = (String)e.nextElement();
      String value = request.getHeader(name);
      System.out.println("   HTTP HEADER: " + name + " = " + value);
   }

The header values I added are NOT there.  Can anyone tell me what I'm doing wrong?  I also tried the response.setHeader("deatail1", "something") method, but that didn't work either.
0
Comment
Question by:dhenderson12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
shinobun earned 900 total points
ID: 17769110
HttpServletResponse#sendRedirect() [1] will only tell the web client to redirect to another page.  The redirect instruction itself will contain your headers, and the following request will have a fresh set of headers.  You might want to check out the RequestDispatcher#forward() [2] method, which will pass on the same request and response.  However, this will only work if it the place you want to redirect to is in the same container.

[1] http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletResponse.html#sendRedirect(java.lang.String)
[2] http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/RequestDispatcher.html#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question