3

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!

2
  • Request headers are independent of response headers, simply because you send a header to the browser in a response doesn't mean it will be repeated in a subsequent request - the header has to mean something to the browser. That's sort of what cookies are for. What header do you want to 'set'? Commented Aug 17, 2011 at 17:53
  • Why do you have to set anything in the http header? If you want to, use the HttpServletResponse and put whatever you like there. Incoming is request, get the SSO/cookie from there, put it in response.setHeader .. ? Commented Aug 17, 2011 at 19:11

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.