2008-11-21 96 views
2

我正在開發一個使用servlets/jsp的在線考試。我需要在結束考試並重定向到結果頁面的問題頁面上添加倒計時(hh/mm/ss)計時器。JSP/Servlets中的倒數計時器

我已完成除定時器之外的所有其他功能。

有人可以提供一些幫助。

謝謝

+0

它是一個很好的問題。很快就會得到答案 – Warrior 2008-12-04 08:31:34

回答

3

您是否試過JavaScript解決方案。它很容易編寫你自己的。網上也有很多例子,例如one

1
<html> 
<%@page session="false" %> 
<% 
HttpSession s=request.getSession(false); 

if(s==null) { %> 

    <jsp:forward page="/Expired" /> 
<% } %> 
<% String duration=(String)s.getAttribute("duration"); %> 
<% int a=Integer.parseInt(duration); %> 
<head><title></title> 
<script type="text/javascript"> 
var cmin=<%= a %>; 
var total=cmin*60; 
cmin=cmin-1; 
var ctr=0; 
var dom=document.getElementById("kulu"); 
function ram(){ 
var dom=document.getElementById("kulu"); 
dom.value=(cmin)+"minutes"+(total%60)+"seconds"; 
<% String t=(String)s.getAttribute("over"); %> 
var tt=<%= t %> 
if(tt=="false"){ram1();} 
total=total-1;ctr++; 
if(ctr==60){ctr=0;cmin=cmin-1;} 
if(total==0){ 
ram1();} 
setTimeout("ram()", 1000); 
       } 
function ram1(){ 

window.location.replace("/hcl/TTimeUp.jsp"); 

       } 
</script> 
</head> 
<body background="image/background.gif" onload="ram()"><center> 
<form name="form1"> 
<input type="text" id="kulu"/> 
</form> 
</center> 
</body> 
</html>