Forums Register Login

How to end an active session using servlets

+Pie Number of slices to send: Send
Hi,
I am making an application for online test. One of the requirements is to end the session of the user must be ended 1 hour after the user logged in.
The time set in web.xml ends a session after the specified time only if the session is INACTIVE.
Please tell me how to kill an active session after fixed time.
Abhishek.
+Pie Number of slices to send: Send
Don't rely on the session timout. Institute your own timer.
+Pie Number of slices to send: Send
What kind of a timer are you talking? Please specify. And how to make such a timer?
+Pie Number of slices to send: Send
 

Originally posted by Abhishek Asthana:
What kind of a timer are you talking? Please specify. And how to make such a timer?



Hi

I think what you're looking for is a TimerTask - see the Java API java.util.Timer and java.util.TimerTask - a good example is at: http://javaalmanac.com/egs/java.util/ScheduleLater.html.

Then it's simply a case of doing at the appropriate time - inside the timer. I'll leave how to attach the timer thread to the session for you to work out

Not really for me to ask - but why would you want to kill a client that's been logged on for an hour. Don't think they'd apprechiate it much! What if they are in the middle of something which involves putting data in the session - are you just going to loose that data? Are you going to tell the user what's happened?

Cheers,
Gray
+Pie Number of slices to send: Send
Hey Gray,
Thanks for the help. I should have thought of it!
Ok I am actually making an application for online test. So examinee has to either logout within 1 hour, or we will disconnect him. Sort of snatching your answer sheets after stipulated time!
Hope this makes sense!
Thanks again
Abhishek.
+Pie Number of slices to send: Send
You can get the time when user logs in by System.getCurrentTime() and then on every page calculate the current time again.If this time is greater than the time when user logs in by one hour then invalidate the session.

Let me know if this approch is right.
+Pie Number of slices to send: Send
Hi Abhishek,
No problem!
I understand what your doing now - still sounds a bit brutal - but we've all sat exams right ;-)
Cheers,
Gray
+Pie Number of slices to send: Send
Ending the test by killing the session is a BAD BAD BAD idea.

THINK! What would you like to happen in a classroom exam when time is up?

Yes, gather the papers and grade them - you can't do that if the session is expired.

Just note the expiration of the time, stop accepting answers, and force the next output to be the grade result.
Mark the session so that the user cant do anything but proceed to whatever final page you want to show, THEN invalidate the session.

Bill
+Pie Number of slices to send: Send
Tell me what kind of test engine u r designing. if u have everything running on the client side u can surely use javascript for this purpose.
if u have frames still u can use javascript. If u r making a trip to server for each section or question then u can think of something request time etc
+Pie Number of slices to send: Send
 

Originally posted by vinod bonde:
Tell me what kind of test engine u r designing. if u have everything running on the client side u can surely use javascript for this purpose.
if u have frames still u can use javascript. If u r making a trip to server for each section or question then u can think of something request time etc



Bad idea, I must say. Never rely on client-side scripting.
[ October 03, 2005: Message edited by: Adeel Ansari ]
+Pie Number of slices to send: Send
What if they're in the middle of a page when the session ends? Or is it question by question? You could always impliment ajax to update the answers every time they answer a question and then stop accepting answers after a certain time. Maybe use both the javascript timer and server side validation in this way... worth checking out? What do the rest of you think?
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3216 times.
Similar Threads
listing all online users on a JSP page
Can Container invalidate the session
Forcing Relogin
session management -session not destroying automatically
Session retention
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:12:23.