Reputation:
I am trying to develop an online exam app with JSP. So I want to link to the results page with the same parameters of the current page (exam page) when a certain period of time runs out. I want to know how to add a timer and how to link to another page when the time is out. Thanks.
Upvotes: 0
Views: 777
Reputation: 876
You need to use Javascript to achieve this. There you'll need to create a JS segment looking something like this:
<script type="text/javascript">
var myTimer = window.setTimeout(timer, 3000);
function timer() {
window.location.href = "new_page.htm"
}
</script>
That script is meant for going into the body section to work. A script for your head section would require an onload event to take care of starting the timer. The example will redirect after 3 seconds.
Upvotes: 3
Reputation: 14642
JavaScript is only client-side, it could be disabled or changed to cheat your application.
You have to keep track of the time at the server too, and you should also try to get input asap to your application, to know if the answer was "in time" or not.
Heavy AJAX is the way I would solve this problem.
Another way could be a Flash/Flex combo with a similar backend.
Upvotes: 1