• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Modifying request header  RSS feed

 
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By modify, I mean adding new values, (String,value) pair from Java class. There is getHeader but no setHeader method.
 
Saloon Keeper
Posts: 4743
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be the point of modifying the request once it arrives at the server? You can use request attributes to attach values to it if you need to.
 
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request headers are set the by the client, not the server.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Saurabh Pillai wrote:By modify, I mean adding new values, (String,value) pair from Java class. There is getHeader but no setHeader method.



Hi,

The request comes from the client. You can change it on the server: by the use of a servlet filter. As other people mentioned, there should not be many situations when you need to do that, however if you do need, register and implement a filter.

Regards,
Daniel
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A filter isn't going to be of much help either. Even ServletRequestWrapper has no way to set headers.

But before even considering something so over-the-top, we need to hear from the OP regarding why he wants to do this. Chances are that setting headers isn;t really what is called for.
 
Daniel Val
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:A filter isn't going to be of much help either. Even ServletRequestWrapper has no way to set headers.

But before even considering something so over-the-top, we need to hear from the OP regarding why he wants to do this. Chances are that setting headers isn;t really what is called for.



I have to admit that I never found use for changing req headers; however there are resources available as follows

http://vangjee.wordpress.com/2009/02/25/how-to-modify-request-headers-in-a-j2ee-web-application/



D
 
Saurabh Pillai
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, sorry for the late reply.

In my web app, at some point we are retrieving the values from header using request.getHeader() method. Now, this values get set from another app. It's like you login to some portal and you have multiple web apps available to use. Now, we don't have any access to the code where values get set in header. But during development, I need to mimic this so I was wondering how the values get set into header? Later on I thought of correct solution to just bypass that code. Now all is well.

But I found out that you actually set the header in response. Now this leads me to another question, I am almost positive, that login to portal and my web app both are different web app. so are they linked through something like ,

reaponse.sendRedirect()?

Thank you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!