• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Passing header parameters with the request

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 7174
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7174
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 7174
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic