• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding custom Header information to the HttpServletRequest object

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi ranchers,

Iam working on a J2EE struts web application. I want to send application information to the server through the Request Headers.

Is there anyway that i can add a custom header information like " isValidUser : true " to the HttpServletRequest object programatically just like we do it using addHeader method in the HttpServletResponse class.

I don't want to send the information through the Request Params / Query string and i want to send application information to the server in the Request Headers Only.

Any alternate way to achieve this ? Thanks in advance for your time and attention.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Venkata.

Add a response header is not working for you?
 
Venkata Sirish
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hebert,

I want to send the data in Request Header not in the Response Header.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The set of request headers - parsed out of the request by the servlet container - that you get in a servlet doGet etc method can not be changed - if you want to add something to a request you can:

1. use the setAttribute method - subsequent code would have to use getAttribute to get the value.

2. create a custom implementation of HttpServletRequestWrapper with special handling of the getHeader method to return the value you want to plug in.


Given that you have setAttribute, I can think of no valid reason to use method 2.

Bill
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'd need to create a ServletRequestWrapper/HttpServletRequestWrapper implementation.

But it depends on how you're making the request--if it's from the JavaScript side via Ajax, most JS libs provide access to the headers. If you're trying to do it via something like a form post you're likely out of luck.

Man, I need to hit send earlier.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic