Perhaps someone here can give me a hand with this because I'm afraid I've run into a bit of a wall on this one.
I'm working on a web application which uses multiple
JSP pages. However, in order for these pages to work properly the user must first come through a single "setup" screen in which they select the site they would like to administer. Without first selecting a site, the other pages won't be able to function.
So, my ideal goal would be to redirect the user back to that "setup" screen any time they try accessing another one of the pages. I thought a Filter would be a perfect way to set this up because I could simply map that filter to the URL
patterns for my various JSP pages and I could write the code to check for a selected site and redirect the user in one place. Unfortunately, despite my plan, things aren't going so smoothly.
First, I wrote a very simple filter that looked like this (this was within the doFilter method):
That code is pretty simple. It just checks for a value in the session and, if it isn't there, it redirects the user back to the home page for the application. Unfortunately, it doesn't work. If I try to execute this, I get an error like this:
I'm not quite certain what's happening here. I was hoping that I could capture the request and re-route it before it ever reached the JSP the user had requested. Instead, I get an error as if there are two places where a response is being created.
I tried putting the redirect after the "chain.doFilter(req, resp);" and that only led to another error message. I've been reading through "Head First
Servlets and JSP" about creating custom Request and Response objects but, in all honesty, I'd read less confusing things in the past.
Anyone out there able to shed a bit of enlightenment on what's going on here and give me some direction. If I could more clearly understand what was going on, I could probably make more headway.
Thanks,
Corey