?
Solved

lil stuck....##??!!

Posted on 2003-03-03
10
Medium Priority
?
168 Views
Last Modified: 2010-04-01
Hey,

ive got a little problem with the app i am developing and am unure of how to go about it.

Scenerio
A user enters info in html form, jsp verfiys info submitted if user is valid and hasant taken test before they are directed to the test page.

(all the above has been implemented)

i want to now time how long it takes the user to complete the test (after they have pressed submit on test page this means they have completed it) and then enter this value in the database as well as checking to see if their answers are correct (i no how to write to the database- but how do i get the time???)

also if the user does not finish within a specfic time ie 10mins then the exam shud be submiited and the databse values updated. and user redirected to another page which tells them of their score/


does ne one no how ii can do this?
how to improve this?
or shud i just try some other way?

thanks in advance ill
0
Comment
Question by:illinosis
[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
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 19

Accepted Solution

by:
cheekycj earned 200 total points
ID: 8059833
two things you can implement (not as replacements but complementing each other)

1. JavaScript timer to let the user know how much time is left for the test (use JSP to popuplate the initial time)
like here:
http://javascript.internet.com/games/count-down.html

2. on the first page store the current time in session using

<% java.util.Calendar startTime = java.util.Calendar.getInstance();
   session.setAttribute("starttime", startTime);
%>
the above is the variable to use to populate the start time in Javascript.

Then you can tell the time difference on the submission page like this:

<%
   boolean inTime = false;
   java.util.Calendar startTime = (java.util.Calendar)session.getAttribute("starttime");
   if (startTime != null) {
     endTime = java.util.Calendar.getInstance();
     // setting end time to start time (initially)
     endTime.setTime(startTime.getTime());
     // adding ten minutes
     endTime.add(java.util.Calendar.MINUTE, 10);
     // if end time is before the current time set inTime to true
     if (endTime.before(java.util.Calendar.getInstance()) {
       inTime = true;
     }
%>
  <% if (inTime) { %>
    finished in time!
  <% } else { %>
   did not finish in time!
  <% } %>
<% } else { %>
  No start time error!
<% } %>

HTH,
CJ
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8059912
for the jsp part, it might be easier do it this way.

when you display the test page:

<% session.setAttribute( "startTime", new Long(System.currentTimeMillis()/60000) ); %>

when user submit result back:

<% long duration = System.currentTimeMillis()/60000 - session.getAttribute( "startTime" ).longValue(); %>

the var duration contains the number of minutes users used to finish the test.
0
 
LVL 92

Expert Comment

by:objects
ID: 8061051
No need to use a Calendar object, simply store a new Date instance as the start time.

Use a meta refresh tag on each page to autorefresh the page after the remaining time has passed.

And when submitted calc time difference as posted above.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:cheekycj
ID: 8064993
agreed that Calendar is not needed, I am too used to writing code that is adaptable to internationalization and java.util.Date is pretty much deprecated - I hate the deprecated warning in my builds :-)

CJ
0
 

Author Comment

by:illinosis
ID: 8066170
thanx for all ure advice...i will play around with the coding tonite and tmor and let u all no if there are ne probs etc...

hopefully it works out...i will post points on thurs after i have tried out ure suggestions.

thanx for everyones input.
0
 
LVL 92

Expert Comment

by:objects
ID: 8069625
> java.util.Date is pretty much deprecated

Date isn't deprecated, just some of it's methods. The Date class itself (and non-deprecated methods) are really independant of i18n.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8072544
4 out of its 6 constructors are deprecated.

Out of its 30 odd methods about 20 are deprecated.

And from Sun's online javadocs:
"Prior to JDK 1.1, the class Date had two additional functions. It allowed the interpretation of dates as year, month, day, hour, minute, and second values. It also allowed the formatting and parsing of date strings. Unfortunately, the API for these functions was not amenable to internationalization. As of JDK 1.1, the Calendar class should be used to convert between dates and time fields and the DateFormat class should be used to format and parse date strings. The corresponding methods in Date are deprecated."

So we pretty much make it a Standard to use java.util.Calendar.

CJ
0
 

Author Comment

by:illinosis
ID: 8073742
well..thanku all for ure help...at the end i decided to use CJ way...ive adapted it to meet my needs...thanx CJ and have also decided to use the timer.

for some reason i kept having errors when trying to do it kennethxu way :(...(cant convert java lang to long...)...

thanku all nehow.

illinosis.
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8073892
Glad I could help and Thanx for the "A"

CJ
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8074508
>> for some reason i kept having errors when trying to do it kennethxu way :(...(cant convert java lang to long...)...
forget to cast the session attribute back to Long, this works for me:

<% if( request.getParameter( "submit" ) == null ) {
     session.setAttribute( "startTime", new Long(System.currentTimeMillis()) ); %>
Submit after finish the test:
<form method=post><input type=submit name=submit></form>
<% } else {
     long duration = System.currentTimeMillis() - ((Long)session.getAttribute( "startTime" )).longValue(); %>
You spent <%=duration/60000%> minutes<p>
You spent <%=duration/1000%> seconds<p>
You spent <%=duration/60000.0%> minutes<p>
<% } %>
0

Featured Post

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!

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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