Solved

How to set times up through out all jsp pages

Posted on 2004-09-11
9
204 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
Comment Utility
> 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
Comment Utility
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
Comment Utility
Use longValue:

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

Hope this helped :-)

Tim
0
 

Author Comment

by:ahwind
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:TimYates
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Dear TimYates,

       Thanks for your comment.

Regards,
ahwind
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
:-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
decryption not working 5 80
logging jar 1 104
main method of string class 3 82
Books that can get me started on JAVA 2 52
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

11 Experts available now in Live!

Get 1:1 Help Now