Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Session Management

 
Shyam Goud
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Shyam Goud
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much Merill. I will the suggested approach.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic