当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用ASP实现网上考试系统

ASP
提高SQL的执行效率的ASP的五种做法
asp的offset的一个go to page
asp中command的在单条记录时,有些字段显示为空的问题
asp,php一句话木马整理方便查找木马
asp 合并记录集并删除的sql语句
asp下循环一行多少个
asp循环行数输出函数
asp access重新开始编号
ASP生成数字相加求和的BMP图片验证码
静态页面利用JS读取cookies记住用户信息
比较详细的Asp伪静态化方法及Asp静态化探讨
asp Response.flush 实时显示进度
Asp高级故障解决以及相关代码
asp智能脏话过滤系统v1.0
ASP文件中的安全问题
Access数据库中“所有记录中均未找到搜索关键字”的解决方法
asp两组字符串数据比较合并相同数据
asp MYSQL出现问号乱码的解决方法
asp文章中随机插入网站版权文字的实现代码
ASP利用XMLHTTP实现表单提交以及cookies的发送的代码

用ASP实现网上考试系统


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 82 ::
收藏到网摘: n/a

随着互连网技术的发展网上教学将成为人们接受再教育和终身教育的主要形式。在网上学校中,人们可以不受时间和空间的限制,随时随地选学任何地方的任何课程。网上学校的发展对网上考试的发展提出了迫切的要求。这里是我用Asp和Access数据库实现的一个网上考试系统。当用户凭用户名和口令登录时,系统首先检查该用户是否已参加过考试,若是则进行成绩查询,若否则从题库中提取考题供用户解答。等用户提交答卷后,系统进行评分并将成绩登记入库。

一. 数据库设计

首先建立一数据库exercise.mdb,其中包括两个表:user和test,user表中有包括三个字段:

字段名称:user;字段类型:文本;字段大小:20。存储用户名

字段名称:passwd;字段类型:文本;字段大小:20。存储用户密码

字段名称:score;字段类型:数字;字段大小:整型。存储用户成绩
test表中有五个字段:
字段名称:question;字段类型:文本;字段大小:255。存储考试题目

字段名称:a;字段类型:文本;字段大小:100。存储选项A的答案

字段名称:b;字段类型:文本;字段大小:100。存储选项B的答案

字段名称:c;字段类型:文本;字段大小:100。存储选项C的答案

字段名称:d;字段类型:文本;字段大小:100。存储选项D的答案

字段名称:ans;字段类型:文本;字段大小:2。存储正确答案

二.程序原代码
  
下面是该系统中较核心的三段原程序,希望对开发类似系统的读者取到抛砖引玉的作用,读者也可对其进行改进以适应自己的系统。

以下为引用的内容:
‘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.MapPath("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="" > < /P >
< P title="" > < /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=" 进入 " style="FONT-SIZE:
medium; FONT-STYLE: normal;
FONT-VARIANT: normal; FONT-WEIGHT:
bold" title="" >< /P >
< 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=""+((hrs >12) ?
hrs-12 : hrs);
document.clckm.disp.value=((min< 10) ? "0" : "")+min;
document.clcks.disp.value=((sec< 10) ? "0" : "")+sec;
document.clck.disp.value=(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 onLoad="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 >< /TD >
< TD VALIGN=TOP >< FORM NAME="clckh" onSubmit="0" >
< INPUT TYPE="text" NAME="disp" SIZE=2 VALUE ="" >
< /FORM >< /TD >
< TD VALIGN=TOP >< FORM NAME="clckm" onSubmit="0" >
< INPUT TYPE="text" NAME="disp" SIZE=2 VALUE ="" >
< /FORM >< /TD >
< TD VALIGN=TOP >< FORM NAME="clcks" onSubmit="0" >
< INPUT TYPE="text" NAME="disp" SIZE=2 VALUE ="" >
< /FORM >< /TD >
< TD VALIGN=TOP >< FORM NAME="clck"
onSubmit="0" >
< INPUT TYPE="text" NAME="disp" SIZE=4 VALUE ="" >
< /FORM >< /TD >< /TR >
< /center >
‘显示试题供解答
< FORM action="result.asp" id=FORM1
method=post name=FORM1 >
< P > < /P >
< P >
  < %
  i=1
  rs.movefirst
  do while not rs.eof% >
  < P > < %=rs("question")% >< /P >
< TABLE align=center border=1 cellPadding=1
cellSpacing=1
width="80%" >
  < TR >
   < TD style="WIDTH: 50%" width="50%"
< INPUT name=ans< %=i% > type=radio value="A" >
< %=rs("a")% >< /TD >
   < TD >< INPUT name=ans< %=i% >
type=radio value="B" >
   < %=rs("b")% >< /TD >< /TR >
  < TR >
   < TD >< INPUT name=ans< %=i% >
type=radio value="C" >
   < %=rs("c")% >< /TD >
   < TD >< INPUT name=ans< %=i% >
type=radio value="D" >
   < %=rs("d")% >< /TD >
  < /TR >
< /TABLE >
< %
i=i+1
rs.movenext
loop
% >
< /P >
< P > < /P >
< P align=center >< INPUT id=submit1 name=submit1
type=submit
value=Submit >< INPUT id=reset1 name=reset1
type=reset value=Reset >< /P >< /FORM >
< /BODY >
< /HTML >

以下为引用的内容:
‘result.asp源程序,对用户答卷评分,
并将分数记录入库
< %@ Language=VBScript % >
< HTML >
< HEAD >
< META NAME="GENERATOR" Content="Microsoft
Visual Studio 6.0" >
< /HEAD >
< BODY >
< P > < /P >
< %
name=session(“user”)
dim score
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver=
{Microsoft Access Driver (*.mdb)};dbq="
& Server.MapPath("exercise.mdb")
sql="select ans from test"
Set rs = conn.Execute( sql )
ycorrect=0
rsCount=0
‘给出正确答案并评分
Response.Write "正确答案:"
Do while not rs.eof
Response.Write rs("ans")
rsCount=rsCount+1
if Request.Form(rsCount)=rs("ans") then
ycorrect=ycorrect+1
end if
rs.movenext
loop
Response.Write "< br >你的答案:"
score=int(ycorrect/rscount*100)
for i=1 to Request.Form.Count-1
Response.Write Request.Form(i)
next
Response.Write "< br >"
Response.Write "你的成绩:"&score
if score< 60 then Response.Write " 你不及格!"&"< br >"
else if score >=60 Response.Write " 及格"&"< br >"
else Response.Write " 优秀!"
‘将成绩登记入库
strSql=”insert into user (result) values (”&score&”)
where user=’”&name&”’”
conn.execute(strSql)
% >
< /BODY >
< /HTML >