aspose file tools*
The moose likes Struts and the fly likes Struts Session Management Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Session Management" Watch "Struts Session Management" New topic
Author

Struts Session Management

Shyam Goud
Greenhorn

Joined: May 29, 2008
Posts: 5
Hi Ranchers,

I am working on an application where i need to implement session management. My application has got 20 Jsp's and the session timeout is set to 15 mins. Now...when i am in 8th page and the session times out....and when i click to goto 9th page....my application redirects me back to the login page. This is absolutely fine.

But..here's the thing....when I login back it goes to the first page of the application instead of 9th page...

I had 2 possible solutions for this....
1. We can store the pageid's in a database and retrieve then when we log back in...(I dont like the idea of making any database changes)

2. when session timesout...b4 i go to the login page...i save the forwardURI and the request parameters in a map...and retrieve these parameters when i login and I decorate the latest request parameters with the old ones that were stored in the map...coz we are still in the session...

When I use the 2nd approach I get an illegal class cast exception when I try to use request.getParameter(paramName);

Can you people suggest me a different approach for this solution or a work around for the exception....Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Uncle Sam,

Please check your private messages for a message regarding an important administrative matter. You can do so by clicking My Private Messages in the upper right corner of the page.


Merrill
Consultant, Sima Solutions
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Pl explain me this,

i save the forwardURI and the request parameters in a map...and retrieve these parameters when i login and I decorate the latest request parameters with the old ones that were stored in the map...coz we are still in the session...


How can one ll be in session and retrieve map , when it invalidate the session after 15 mins ??
[ May 31, 2008: Message edited by: Sagar Rohankar ]

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Shyam Goud
Greenhorn

Joined: May 29, 2008
Posts: 5
Hi sagar,

I assume that eventhough the session is timedout, it would still be there unless we cleanup the request parameters.

When I relogin after session time out....In the RetrieveRequestParameters()...I would just say
HttpSession session = httpRequest.getSession(true);
if(session != null){
Map savedParams = (Map) session.getAttribute(REQUEST_PARAMS);

if (savedParams == null)
return httpRequest;
return new SessionStateDecorator(httpRequest, savedParams);
}
return httpRequest;

And this is actually working....and i can see these parameters while in debug mode..I used the following example since it matches my requirement exactly...plzz go through the link

http://today.java.net/pub/a/today/2007/01/04/transparent-state-management-using-decorator-pattern.html
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Shyam Goud:
I assume that even though the session is timed out, it would still be there unless we clean up the request parameters.[/URL]

No, that is not the case. When a session times out, the HTTPSession object is out of scope and can no longer be accessed. The getSession method on the request will return a new HTTPSession that has no objects attached to it.

To solve this problem, I'd suggest you create a hidden field in each page containing the URL for the page. That way, if the user clicks the submit button, the URL is also submitted along with the request and can be accessed by your login action. It can then check if the URL is not null and forward to it after the user logs in again.
[ June 01, 2008: Message edited by: Merrill Higginson ]
Shyam Goud
Greenhorn

Joined: May 29, 2008
Posts: 5
Thanks very much Merill. I will the suggested approach.
 
Don't get me started about those stupid light bulbs.
 
subject: Struts Session Management