• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Servlet - Servlet Communication - Setting the headers

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey people,
This is the scenario.. I need to send a custom value in the header of my request alongwith the normal request headers and then retrive it in the destination servlet. For eg, I want to send the user name in the header of the request, whether it is from a servlet or from a JSP, and then retrieve the value in the servlet that processes the information. If it is a servlet to servlet communication, can the response headers be used to set and retrieve the value....? Someone plzzzzz advice in this regard and it is a bit urgent. Thanks in advance for the help. You can mail me at abhishek.dwaraki@gmail.com if you come up with anything plz.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you just append the value as a request parameter?

like: myapp/whatever.html?userName=ziggy

/M
[ April 07, 2006: Message edited by: Manuel Palacio ]
 
Marshal
Posts: 28296
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
What request is this that you want to attach headers to? Were you hoping that by attaching a header to your response, the client (browser) would kindly copy it over to the next request it sends to your host? That isn't going to work. You say

I want to send the user name in the header of the request, whether it is from a servlet or from a JSP

but that doesn't make much sense, because servlets and JSPs don't send requests. They send responses to requests.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain why do you want to put user name in the headder and send it, when there are other ways to send the parameter.

Putting username in headder is not a good idea.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In which senarios we put data in response header?



Thanks
Prakash
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If it is a servlet to servlet communication



=> are you talking:
1) of a servlet forwarding a request to another servlet or JSP before reponding to the client?
2) of a servlet processing a request, saving some info about it, sending a response to the browser and expecting to get the info back when getting another request from the save client?

In the first case, you would rather put your info in an attribute of the ServletRequest and not in a a parameter. This info disapears as soon as the response is sent to the client. Have a look at ServletRequest.setAttribute(String, Object).

If you want to keep some info during several requests of the client, you wan to put the attribute in the HttpSession. Have a look at ServletRequest.getSession() as well as at this encoreURL thing.


Cheers
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by siva prakash:
Hi,

In which senarios we put data in response header?



Thanks
Prakash



As application developers, we shouldn't really have to.
The headers are for manipulating aspects of the HTTP protocol.

Some cases where an application developer might find him/herself writing headers would be servlet/applet communication. You would, of course, need to understand HTTP headers if you were to write your own web client.

I built a component for an application that served up some server side dynamic CSS. By working with the If-Modified-Since and Date headers I was able to get the browser to use it's cached version of the CSS sheet when there were no changes. This cut down on a lot of bandwith usage.

I would be very hesitant to start adding my own headers just to pass information back and forth between server side components. That's what querystring and post parameters are for.
 
Politics is a circus designed to distract you from what is really going on. So is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic