Solved

How to set times up through out all jsp pages

Posted on 2004-09-11
9
209 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
report generation frameworks 1 73
Using Tomcat as raspberry pi java app server 13 283
struts hibernate integration example 28 157
iterator/ListIterator approach 17 68
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our systems…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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