Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Modifying request header Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Modifying request header" Watch "Modifying request header" New topic
Author

Modifying request header

Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 506
By modify, I mean adding new values, (String,value) pair from Java class. There is getHeader but no setHeader method.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Jan 10, 2002
Posts: 60774
    
  65

Request headers are set the by the client, not the server.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Daniel Val
Ranch Hand

Joined: Jan 09, 2012
Posts: 44
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

Joined: Jan 10, 2002
Posts: 60774
    
  65

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

Joined: Jan 09, 2012
Posts: 44
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

Joined: Sep 12, 2008
Posts: 506
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Modifying request header
 
Similar Threads
About websphere xa datasource
InnerClass Question
passing the objects
Database Connection and Operations
how to update only the modified field values