permaculture playing cards
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
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: 13037
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 ]
It is sorta covered in the JavaRanch Style Guide.
subject: how to set the header in http request object ?
It's not a secret anymore!