• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Modifying request header

 
Saurabh Pillai
Ranch Hand
Posts: 524
  • 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.
 
Tim Moores
Bartender
Posts: 2856
46
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
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.
 
Daniel Val
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
Pie
Posts: 64994
86
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: 524
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic