File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Passing header parameters with the request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing header parameters with the request" Watch "Passing header parameters with the request" New topic
Author

Passing header parameters with the request

Sanjaykar Gurram
Greenhorn

Joined: May 05, 2008
Posts: 22
Hi

I have the requirement of passing header parameters along the request(not as request parameters, value need to be send via header information).

I googled to find if there is any possibility to send header information using javascript, but in vain.
I also tried using servlet response.sendRedirect() like as shown below:

String redirect_uri = "https://localhost:8080/MyApp";
response.addHeader("ACT", "TEST");
response.sendRedirect(redirect_uri);

The request gets redirected but the header value do not get passed, as the browser makes a new request which do not contain the header information i put in the servlet. Kindly suggest me a way i can pass information to my application url via headers.

Thanks,
Sanjaykar
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
From where to where are you trying to pass information? From the browser to the server? After a redirect? Then you'll have use parameters, since headers aren't preserved through a client-side redirect.
Sanjaykar Gurram
Greenhorn

Joined: May 05, 2008
Posts: 22
Actually i want to make a client side redirect (i.e, when you click a hyperlink on the browser you will be redirected to a different url passing few header parameters along the request).

I tried to do this from javascript as well as servlet redirection. Both ways did not succeed me.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If you use XmlHTTPRequest from within JavaScript then setting headers is possible. Not by following a link in the HTML page.

Why do you want to use headers instead of URL parameters?
Sanjaykar Gurram
Greenhorn

Joined: May 05, 2008
Posts: 22
My client server expects few parameters only as part of the header and not in the request.

So do you want me to use XMLHttpRequest which is an ajax style of call, right? Is that possible to redirect to the url from the browser using XMLHttpRequest ?

Thanks.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Why is the server expecting headers from the client if the client can't set those?

Is that possible to redirect to the url from the browser using XMLHttpRequest ?

No. Such a request is sent from JavaScript running in a web page. That was just an example of how to send headers. If this is a browser responding to clicks on links and such, then you need to use URL parameters and HTML forms to transfer data.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing header parameters with the request