Storing a request for later use
My site is password protected and stores information about the user in the session. What I'd like to do is set my site up so that if the users session times out and then they click a link they will be redirected to the login page. If the login is successful they should then be redirected to the page they were attempting to go to.
I have got this working up to a point by storing the URI and request Query they were attempting to access when I detected the session time out.
What I'd like to do is store a copy of the actual request so that if I detected a time out while they were submitting a form I can use the stored copy of the request for processing once I have authenticated the user.
I've tried storing the request as a session attribute but it gives wierd results.
If (session.getAttribute("OldRequest") == null)
returns false but
((HttpServletRequest)session.getAttribute("OldRequest")).getRequestURI() results in a null pointer error.
I suspect that the request is being automatically invalidated when I shunt the user off to another page but I'm not sure.
You could store the last requested page in a database and reference that if necessary.
One method would be to use a controller servlet to process incoming requests. The advantage of this is that you can have it process an information-bean that can be saved to a session before checking if the user is logged in. If the user isn't logged in, they can be forwarded to the login page and then redirected back to the requested source. Their originally submitted info will be in the session at that point as the bean. All jsp's will use an information bean instead of getting any info from the request. This is all possible with Struts. You might want to check it out.