Solved

problem adding response headers in servlet

Posted on 2006-10-19
1
463 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
1 Comment
 
LVL 9

Accepted Solution

by:
shinobun earned 300 total points
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now