Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

problem adding response headers in servlet

Posted on 2006-10-19
1
Medium Priority
?
478 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 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

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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

916 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