This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to set the header in http request object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to set the header in http request object ?" Watch "how to set the header in http request object ?" New topic

how to set the header in http request object ?

Moushumi Das

Joined: Jul 09, 2004
Posts: 1
I am facing a problem while trying to test a particular flow of my application.The details are given below:

The controller servlet of my main application reads the header "Referer" from the request object and then based on this it forwards the request to appropriate servlets.For testing my application I am writing a test servlet which receives a request object from a test jsp and sets all the necessary attributes in the request object and passes this request object to the doGet () method of the main application's controller servlet. But while trying with this I find that the main controller fails to forward to the correct servlet because it receives incorrect referer information. So my question is how can I set my customised "Referer" in the header of the http request so that the application's controller servlet forwards to the correct servlet?Is there any means to set the request header in servlet or jsp?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12761
This sounds like a job for a custom implementation of HttpServletRequestWrapper. Because you can not directly set a request header value.
Your request wrapper would just provide a version of getHeader that watches for a "Referer" request and returns your test value. All other calls being handled by the wrapped request.
[ July 09, 2004: Message edited by: William Brogden ]
jQuery in Action, 2nd edition
subject: how to set the header in http request object ?
Similar Threads
How to set custom HTTP header for single sign on
Referring web page
How to print the Java data from a JSP
getHeader("Referer") not working on Tomcat 4.1.24
Http header 'referer' NULL in Servlet for pop-up window