I am adding one custom header "edmsversion" in my first page, it is visible in it but when the response is redirected to another jsp, my header is lost. In second page, it's not getting. I have copied my code below.
Please help me.
My first Page
-------------------------
System.out.println("Jsp called successfully");
response.addHeader("edmsversion","1.2");
boolean isheader = response.containsHeader("edmsversion");
System.out.println("contains edmsversion header ..."+isheader);
response.sendRedirect("/TestHeaderResponse.jsp");
TestHeaderResponse.jsp
----------------------------------
System.out.println("Test header response page called successfully");
String stringversion = request.getHeader("edmsversion");
System.out.println("edms version header : "+stringversion);
Enumeration headernames = request.getHeaderNames();
System.out.println("Headers---------");
while (headernames.hasMoreElements()){
String headername = (String)headernames.nextElement();
String headervalue = request.getHeader(headername);
System.out.println(headername+"----"+headervalue);
}
-
How to add and retrieve http headers (6 messages)
- Posted by: preeti malik
- Posted on: April 24 2002 03:04 EDT
Threaded Messages (6)
- How to add and retrieve http headers by Mark Buchner on April 24 2002 04:52 EDT
- How to add and retrieve http headers by preeti malik on April 24 2002 05:24 EDT
- How to add and retrieve http headers by Steve Albee on April 24 2002 11:56 EDT
- How to add and retrieve http headers by preeti malik on April 25 2002 00:29 EDT
- How to add and retrieve http headers by preeti malik on April 25 2002 00:31 EDT
- How to add and retrieve http headers by Steve Albee on June 05 2002 12:40 EDT
-
How to add and retrieve http headers[ Go to top ]
- Posted by: Mark Buchner
- Posted on: April 24 2002 04:52 EDT
- in response to preeti malik
I believe if you "forward" rather than redirecting then your header information should be ok. As far as I am aware the response is considered "committed" (if you sendRedirect) and cannot be used, in terms of supplying information from one page to the next.
Try using RequestDespatcher.forward or PageContext.forward or the jsp forward tag (depending upon your need) - they all result in the request, response being supplied to the next page/servlet.
Hope that helps.
Mark Buchner
n.b. be sure to makes changes to the header (incl. cookies, etc) *before* you perform the forward operation - goes without saying really. -
How to add and retrieve http headers[ Go to top ]
- Posted by: preeti malik
- Posted on: April 24 2002 05:24 EDT
- in response to Mark Buchner
Hi Mark Buchner,
Thanks for the response.
I have already tried RequestDispacher and jsp:forward. It is not working. Is there any other way of calling another jsp/ servlet so that the header info can be retrieved.
Is there any pre-requiste/ constraint for adding header??
Preeti
-
How to add and retrieve http headers[ Go to top ]
- Posted by: Steve Albee
- Posted on: April 24 2002 11:56 EDT
- in response to preeti malik
In this situation, you may be better off using the HttpSession object. We had to write code that manipulated the header variables, and it got pretty complicated. We ended up having to intercept the request, and manually append headers, and then forward the request. -
How to add and retrieve http headers[ Go to top ]
- Posted by: preeti malik
- Posted on: April 25 2002 00:29 EDT
- in response to Steve Albee
Hi Steve Albee,
My need is to add the http header only. I cann't do it using session object. Do you have any other idea?? -
How to add and retrieve http headers[ Go to top ]
- Posted by: preeti malik
- Posted on: April 25 2002 00:31 EDT
- in response to Steve Albee
Hi Steve Albe,
Can you please send me the code in which you have manually appended the headers??
Thanks
-
How to add and retrieve http headers[ Go to top ]
- Posted by: Steve Albee
- Posted on: June 05 2002 12:40 EDT
- in response to preeti malik
Hi Preeti,
The code I refered to is available in "Java Examples in a Nutshell" from O'Reilly. Take a look at the Server and ProxyServer classes.