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
Solved

How to set times up through out all jsp pages

Posted on 2004-09-11
9
207 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
attribute vs parameter and setter vs add method 17 87
reflection example 3 110
dynamic reloading of jsp in jetty 2 121
collection output issue 9 36
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

790 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