首页 > 代码库 > 案例:如何实现网上考试?

案例:如何实现网上考试?


下面就是满足你设想的几个主程序,你还可以在实际应用中不断完善和扩充:

login.asp 
‘ 考生验证 
<%@ Language=VBScript%> 
<% 
name=trim(request("name")) 
passwd=trim(request("passwd")) 
if name<>"" and passwd<>"" then 
‘ 检查考生是否输入用户名和密码 
Set conn = Server.CreateObject("ADODB.Connection") 
conn.Open "driver={Microsoft Access Driver(*.mdb)}; 
dbq="& Server.MapPat("exercise.mdb") 
set rs= server.createobject("adodb.recordset") 
sql= "select * from user where user= 
‘" &name&"‘ and passwd=‘" & passwd &"‘" 
Set rs= conn.Execute(sql) 
‘ 验证考生合法性 
if not(rs.eof) then 
if rs("score")<>0 then 
‘ 检查考生是否已参加过考试,若是则进行成绩查询 
response.write rs("user")&"的考试成绩是"&rs("score") 
else 
session("pass")=1 
session("user")=name 
response.redirect "test.asp" 
end if 
else 
Response.Write "噢,您输入的用户名或密码不正确!" 
end if 
else 
end if 
%> 
<HTML> 
<HEAD> 
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> 
<TITLE>精彩春风之考生登录</TITLE> 
</HEAD> 
<BODY> 
<FORM action="login.asp" id= 
FORM1 method=post name=FORM1> 
<P title="">&nbsp;</P> 
<P title="">&nbsp;</P> 
<P title="" align=center>考生: 
<INPUT id=text1 name=name style="HEIGHT:22px; WIDTH: 103px"></P> 
<P title="" align=center>密码: 
<INPUT id=password1 name=passwd style="HEIGHT: 23px; WIDTH: 101px" type=password></P> 
<P title="" align=center> 
<INPUT id=submit1 name=submit1 type=submit value=http://www.mamicode.com/"进入 " style="FONT-SIZE: medium; FONT-STYLE: normal; FONT-VARIANT:normal; FONT-WEIGHT: bold" title="">


<P title="" align=center> 
</P> 
</FORM> 
</BODY> 
</HTML>

test.asp 
‘ 从题库中取题考试 
<%@ Language=VBScript %> 
<% 
if session("pass")<>1 then 
response.redirect "login.asp" 
else 
end if 
Set conn = Server.CreateObject("ADODB.Connection") 
conn.Open "driver={Microsoft Access Driver (*.mdb)}; 
dbq="& Server.MapPath("exercise.mdb") 
sql="select * from test" 
Set rs = conn.Execute( sql ) 
‘ 提取试题 
%>

<SCRIPT LANGUAGE="JavaScript"> 
var isn1=null; 
var isn2=false; 
today=new Date(); 
function stopit(){ 
if(isn2){ 
clearTimeout(isn1); 

isn2 = false; 

function startit(){ 
stopit(); 
isnclock(); 

function isnclock(){ 
var now=new Date(); 
var hrs=now.getHours(); 
var min=now.getMinutes(); 
var sec=now.getSeconds(); 
document.clckh.disp.value=http://www.mamicode.com/""+((hrs>12) ? hrs-12 : hrs);
document.clckm.disp.value=http://www.mamicode.com/((min<10) ? "0" : "")+min;
document.clcks.disp.value=http://www.mamicode.com/((sec<10) ? "0" : "")+sec;
document.clck.disp.value=http://www.mamicode.com/(hrs>=12) ? "p.m." : "a.m.";
isn1=setTimeout("isnclock()",1000); 
isn2=true; 

</SCRIPT> 
‘ 以上是一个计时函数

<HTML> 
<HEAD> 
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> 
</HEAD> 
<BODY onl oad="startit()" BGCOLOR="FFFFFF"> 
<center> 
‘ 调用计时函数显示时间 
<TABLE BORDER=2> 
<TR> 
<TD>Time</TD><TD>Hour</TD><TD>Min</TD><TD>Sec</TD><TD></TD> 
</TR> 
<TR> 
<TD>