Solved

How to set times up through out all jsp pages

Posted on 2004-09-11
9
206 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery - parsing the results returned from webmethod 1 112
grep code 4 183
memory representation of int[][][] a=new int[2][][]; 10 60
print map entry 34 69
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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