• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to set and get header info?

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use request.setAttribute("user","admin");
or request.setParameter("user","admin");
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



There is no such method.
reply
    Bookmark Topic Watch Topic
  • New Topic