• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to end an active session using servlets

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't rely on the session timout. Institute your own timer.
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of a timer are you talking? Please specify. And how to make such a timer?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Abhishek Asthana
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Graham Lewis
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abhishek,
No problem!
I understand what your doing now - still sounds a bit brutal - but we've all sat exams right ;-)
Cheers,
Gray
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic