This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes timer in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "timer in jsp" Watch "timer in jsp" New topic
Author

timer in jsp

santosh mohanty
Greenhorn

Joined: Mar 25, 2004
Posts: 1
I am preparing an online examination s/w using jsp and oracle.For every exam session there is a fixed time to be kept eg. 30 mins
after which the page should become inactive.Also the time has to be shown on top of the page which is decremented every second.On each page there is a next button on clicking, the next question is posed.The timer should be for the whole exam session.after the timer expires the form should automatically expire
Please help.
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Moving to JSP forum.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I see no way how you can solve this with a JSP, Javascript would help here if a counter decrements and submits the form after 30 minutes.
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
You can use an applet to control the timer, but I try to stay away from applets (it's been so long, I've even forgotten the reason why). Or, you can use javascript to control the timer, and after, say 25 minutes, you can bring up an alert box saying "5 mins. left" or whatever, then at 30 minutes, you redirect them to an exam completion page. The trick about this method is...you cannot leave the page because the javascript timer exists only at the page level, and once you leave the page, it is lost (unless you store the value in a form, submit to next page, etc. but this really will not work if we're talking about a timer.
So, basically, try to keep your exam limited to one page. You may be able to use an IFRAME to scroll through pages, keeping the timer info on the parent page, or you can simply have the exam all on one page. Either way, this probably does not involve JSP as much as javascript and some good HTML design work.


for (int i = today; i < endOfTime; i++) { code(); }
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60743
    
  65

Moving to the HTML/Javascript forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is a problem with using JavaScript to do this...
The person can disable it and the timer will not work.
But this is what you really need to:
On the server side you have to put a validation to check the time. If the time is greater then the time limit plus a little extra time for processing, then you just do not allow it to submit and give a zero or something to that affect. (You might put a disclaimer stating that.)

With javascript you just need to use a setTimeout and document.FormName.Submit();
Eric
rekha vedali
Greenhorn

Joined: Sep 02, 2003
Posts: 5
Could you please tell me how to display a timer in a JSP page, say having 1hr 30 min and have it count down to zero.
Is there any predefined function in JavaScript or a tag in JSP or in HTML?
Thanks,
rekha
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Look Here
rekha vedali
Greenhorn

Joined: Sep 02, 2003
Posts: 5
Thanks Eric for the link. I have written the �Countdown timer function� using JavaScript in JSP (using struts tags). I got a problem trying to open the application in the browser with tomcat . When I was trying to open with internet explorer or other browsers it is working fine without tomcat running.
Does any one have any idea. If anyone has time to look at my code I will send it.

Thanks,
Rekha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: timer in jsp
 
Similar Threads
how to create timer in jsp?
How to display the timer in jsp page???
how to create timer in jsp page
how to create timer in jsp page ?
how to create timer in jsp