aspose file tools
The moose likes JSP and the fly likes how to set and get header info? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "how to set and get header info?" Watch "how to set and get header info?" New topic
Author

how to set and get header info?

sachin yadav
Ranch Hand

Joined: Nov 24, 2005
Posts: 156
hi,


i want to put following in my one.jsp

response.setHeader("User", "admin");

and then the page will be redirected to two.jsp, where i am extracting this info.

String uname=request.getHeader("User");

but in two.jsp i am getting anull value for uname. what should i do?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14672
    
  11

This won't solve your problem but

1. You're setting a response header, maybe forwarding to another jsp file, and getting the request headers. That does not make much sense.

2. It does not sound appropriate to use http headers for this. Why don't you
use request attributes ?


[My Blog]
All roads lead to JavaRanch
Ramesh Sankar
Greenhorn

Joined: Mar 30, 2006
Posts: 8
use request.setAttribute("user","admin");
or request.setParameter("user","admin");
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Setting a request header is not going to work either. Notice that sachin said "the page will be redirected". Redirecting causes the client browser to generate a new request, and the old request disappears.

The usual way to preserve information from one request to the next is to store it in the user's session. If that is not practical then another way to do it is to write the information out into hidden fields that will be submitted as part of the next request; for a redirect, this means something like appending "?User=admin" to the URL being redirected to.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

Originally posted by Ramesh Sankar:
use ... request.setParameter("user","admin");


There is no such method.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how to set and get header info?
 
Similar Threads
Problem with the query in JDBC ,resultset empty
jsp:getProperty calling bean from specific scope
Hidden Fields in JSP
a href with frames
How to get Requesting URL