Alerting the user about Session expiry when he revisit after idle-time.
Hello,
I have the Web application in which i am using Weblogic Server with Jsps. My requirment is to alert user prior to the session expiry when he revisit the page after the idle-time.
ISSUE is:
"When a user is on a page for longer than the required time he is timed out. There is a time-out value on the server that I need to capture and produce an alert box on the page. "
SOLUTION tried:
For this i tracked the values from javax.servlet.http API
1.Login time,
2. time out value from web.xml
3.idle time(Not able to track)
Please suggest me the solution for this, I mean to say is there any readymade plug-in, Stepspresent.
If not then how can i track the idle time for multiple user.
Do reply me ASAP,
Thanks,
Prasad
You should really be using Interface HttpSession methods. There you have.
session.setMaxInactiveInterval(int interval)
session.getMaxInactiveInterval()
session.invalidate()
session.getLastAccessedTime()
session.getCreationTime() ....etc
NOTE: Servlet sessions (and JSP sessions too since they're the same thing) have a timeout period controlled by a node in web.xml, in the following format:<session-config>
<session-timeout>60</session-timeout>
</session-config>
I think usually it represents the number of minutes since the session was last used. Let me know if you need any further help. Hope that helps. Good luck.
Thanks Varidhi,
Thnaks for ur inputs but I already worked on this.
The methods you have given are really helpfull to get the
1.Creation Time of Session,
2.Time-out value(i.e Value for Session Life)
My Ques is when user revisit the page after idle time ,will session be renewed for next 30 min(i.e value of Time out) from that time instance?
If this is the case then How can i track-down the idle time of user?
Please help me further ASAP,
Regards,
Prasad
It may be possible via javascript. What you can do is set the session expiry as a javascript variable, fire off a javascript function (on body load) that begins couting from zero and when it reaches the limit set in the variable, pop an alert msg. This is theorotical and you should explore javascript programming to check out its feasibility.
ram.
Thanks ram,
I got the solution, Means i tried to capture the Time-out value from the getMaxInactiveInterval().
Cases are
On "OK" click =>I passed session.getMaxInactiveInterval() value to a .js include file (function on <body> of jsp)& from this function i made the logic so that to alert in JAVASCRIPT, On clicking on ok it will rehit the same link.
Here in one more problem,
Now on "CANCEl" => I want to invalidate the session & make the user to login again?
How can i do that in js file itself, becoz here i cannot access the session var & for that i need to return back to jsp?
Do help me
Prasad