Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Adding Custom Data to Response Headers?

 
Greenhorn
Posts: 12
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

If i add a custom header to the HttpServletResponse object, like say,



and then do a response.SendRedirect(URL) to some other URL, will i be able to read this header value at that app?

I've tried this with 2 dummy servlets in different apps but doesn't seem to be working. Am i getting something wrong here or am i trying something which is not right?

At the redirected URL, i retrieve the headers using request.getHeader(headerName);

TIA
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried this sample Program :



I have used JMeter tool to observe the Response Data from the Servlet See the screen shot attached )
What i want to say is , It works the custom response headers will also be added .




Post.jpeg
[Thumbnail for Post.jpeg]
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

and then do a response.SendRedirect(URL) to some other URL, will i be able to read this header value at that app?


No. The response headers are read by the client and then discarded. (Besides, they're response headers, and thus not part of a request.) You'll need to put any data you want to reach the final destination as URL parameters.

Ravi Kiran Va wrote:...


There's no redirection here, so the example is not relevant.
 
Saiprasad Natarajan
Greenhorn
Posts: 12
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

I am passing the data using query parameters but i was just wondering if there is a way to differentiate between a redirect and when someone accesses the app from the address bar directly.


Thanks
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks ulf for the relavant answer . (There should be some clapping Icon on the Icons List )
 
What's that smell? Hey, sniff this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic