Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom HTTP REQUEST HEADER

Tags:

jsp

I need to set a custom header within my JSP based on value I retrieve from a cookie. This cookie is set by a Single Sign On (SSO) service but all it does is set a cookie once the user is authenticated and then it redirects back to a JSP (mine) or whatever URL I supply. It doesn't set anything in the HTTP HEADER so I have to do this somehow. It must be the the HEADER because that is the only way for the Trusted Authentication Service (TAS) URL that handles login to retrieve this value.

I thought I could simply use the response.setHeader method within my JSP and then redirect to the necessary URL for login. I thought this would mean that this custom header would now be part of the REQUEST. It sounds like this can't be done however. I've been told that I could create a Filter that wraps the HttpServletRequest in my own subclass of HttpServletRequestWrapper. Override the getHeader() method to return my custom header, or return the regular header. I really don't know what this means or how I can do this from my JSP.

Any help is GREATLY appreciated!

like image 347
vibhas Avatar asked Sep 15 '26 11:09

vibhas


1 Answers

I think they're are good tutorial on the net on how to create a servlet filter.

Basically a filter will 'intercept' the request and do something special with it (i.e. call a special class)

I think you could do your redirect from that class.

Just saw this to get you started :

http://viralpatel.net/blogs/2009/01/tutorial-java-servlet-filter-example-using-eclipse-apache-tomcat.html

like image 60
Jean-Francois Dionne Avatar answered Sep 17 '26 14:09

Jean-Francois Dionne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!