Solved

How to set times up through out all jsp pages

Posted on 2004-09-11
9
205 Views
Last Modified: 2010-04-01
Dear all,

My jsp is about learning language.User can login to access the online test whereas admin can add question for the test .there are several types of questions such as fill-in-the-blank ,multiple choice and dictation. Besides,there are several rules and regulations that need to be obeyed. User have to login and select which test to be taken ( quiz 1,quiz 2..).once user is login successfully, they can choose freely which type of questions (fill-in-the-blank,multiple choice..) that they want to answer. but they have to answer all questions in those parts within the certain duration(e.g. 1 hour). Furthermore, each user can only login once for each test. The marks are then accumulated and stored in database.

What is the best way to ensure user login once for each test only?The user should be alert once the session is times up and redirect them to page that display their result for each parts. So how to determine their session is expired and display time remaining in status bar while they explore through out each page? I found an example that display remaining time that invoked in body onload event. but the remaining time is not run once i explore to other page.and run again when i explore to that page. i also encounter problem that the remaining time is 'refresh' if i clicked on the Refresh button. how to i keep the remain time while session is valid ?last but not least,if multiple users is accessing the page, how to keep their respective remaining time?

Your help and opinion are much appreciated. that's better if you can provide example code. thanks in advance!

0
Comment
Question by:ahwind
  • 5
  • 4
9 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12043029
> how to i keep the remain time while session is valid

Store the start time in the user's session, then you will know when they started the test and be able to work out how long they have left

> last but not least,if multiple users is accessing the page, how to keep their respective remaining time?

Each user gets their own session, so this would fix this too...

StartTest.jsp:

<%
    session.setAttribute( "TestId", new Integer( testId ) ) ;
    session.setAttribute( "StartTime", new Long( System.currentTimeMillis() ) ) ;
%>
0
 

Author Comment

by:ahwind
ID: 12071631
Dear TimYates,

         I can use session.setAttribute( "StartTime", new Long( System.currentTimeMillis() ) ) to know the session creation time. but how to i convert "StartTime" variable (java.lang.long) to long data type, so that i can perform numerical operation on it?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12072521
Use longValue:

Long time = (Long)session.getAttribute( "StartTime" ) ;
long t = time.longValue() ;

Hope this helped :-)

Tim
0
 

Author Comment

by:ahwind
ID: 12153999
Dear TimYates,

I store the duration of test in database as int data type. how should i write the code to get the absolute remain time? remain time = test duration - (current time - session creation time)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:TimYates
ID: 12154077
yup...  that would do :-)

Long time = (Long)session.getAttribute( "StartTime" ) ;
long t = time.longValue() ;

long remain = duration - ( System.currentTimeMillis() - time ) ;
0
 

Author Comment

by:ahwind
ID: 12178487
Dear TimYates,

I can't get the exact remain time in minutes and seconds. So may i know how to set the long remain as 'Minutes:Seconds'?Thanks.

Regards,
Yee Ling
0
 
LVL 35

Accepted Solution

by:
TimYates earned 250 total points
ID: 12178506
remain is in milliseconds, so you would do:

long minutes = remain / 60000 ;
remain -= minutes * 60000 ;
long seconds = remail / 1000 ;
remain -= seconds * 1000 ;

System.out.println( minutes + "m:" + seconds +  "s:" + remain + "ms" ) ;
0
 

Author Comment

by:ahwind
ID: 12226260
Dear TimYates,

       Thanks for your comment.

Regards,
ahwind
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12226430
:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JspWriter.write() and JspWriter.print() 4 82
unit test DAO layer 1 134
constructor overloading 2 79
main method of string class 3 103
In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now