网络编程
位置:首页>> 网络编程>> Asp编程>> asp网上考试设计思路是怎样的?

asp网上考试设计思路是怎样的?

  发布时间:2010-07-14 21:09:00 

标签:考试,asp

网上考试设计思路是怎样的?

为了运行这个应用程序,我们需要在global.asa文件里进行设置数据库的连接。

global.asa 

< SCRIPT LANGUAGE=VBScript RUNAT=Server >
Sub Application_OnStart
   dbPath = "DBQ=" & Server.Mappath("onlinetest.mdb")
   dbConnectionString =  "DRIVER={Microsoft Access Driver (*.mdb)}; " & dbPath
   Set Application("Conn") = Server.CreateObject ("ADODB.Connection")
   Application("Conn").Open dbConnectionString
End Sub
Sub Application_OnEnd
   Application("Conn").Close
   Set Application("Conn") = Nothing
End Sub
Sub Session_OnStart
End Sub
Sub Session_OnEnd
End Sub
< /SCRIPT >

注册页面index.asp。其中有两个输入域:用户名和口令,这两个输入域需要客户机端的JavaScript确认,以便不把它们作为空白域来传递。非考生要想参加考试必须先注册。这个页面还要显示一些错误信息,如“用户名或口令错误”、“请重新选择一个用户名”等。注册表单中还应包含考生一些个人的信息,如Emai、年龄、教育程度等。登录后,考生就可以参答考试站点的其它试卷了。
index.asp

<title>网上考试设计思路 - www.cidianwang.com</title>
if (theForm.username.value == "")
{
alert("考生姓名\"User Name\"");
theForm.username.focus();
return (false);
}
if (theForm.password.value == "")
{
alert("考生口令\"Password\"");
theForm.password.focus();
return (false);
}
< table border="0" cellpadding="0" >
< tr >
< td width="50%" >
< font face="Verdana" size="2" >姓名:< /font >
< /td >
< td width="50%" >
< font face="Verdana" size="2" >< input type=text name=username size=20 maxlength=50 >< /font >
< /td >
< /tr >
< tr >
< td width="50%" >
< font face="Verdana" size="2" >口令:< /font >
< /td >
< td width="50%" >
< font face="Vedana" size=2 >< input type=password name=password size=20 maxlength= 50 >< /font >
< /td >
< /tr >
< tr >
< td width="100%" colspan="2" align="center" >
< font face="Verdana" size="2" >< br > < input type="submit" value="提交" name="B3" >
< input type="reset" value="重写" name="B4" >
< /font >
< /td >
< /tr >
< /table >

登录文件register.asp,当考生登录或新注册后,就显示这一页。我们可以利用它来询问考生的个人信息。该表单被提交后,转到sendregister.asp页面。

验证和发送文件sendregister.asp。该页面从register.asp 中取得表单域的内容,查询数据库验证输入的用户名是否已经存在,如果存在,则将考生重新引回register.asp页面,并被提示要求重新选择用户名;如果用户名通过,则输入的内容就被传递并插入到数据库中。
sendregister.asp

sql_findmember = "select count(*) from loginuser where username = '" & username &"'"
Set RS_findmember = Application("Conn").Execute(sql_findmember)
If RS_findmember(0) < > 0 Then
Session("message") = "噢,您输入的名字已经存在,请重新选择一个名字!"
response.redirect "register.asp"
' 如果RS_findmember(0) 返回的值大于0,用户就被引导回注册主页,并被要求填写一个新的用户名
End If
If RS_findmember(0) = 0 Then
sql_insert = "insert into loginuser (username,useremail,password) _
values('" & username & "','" & useremail & "', '" & pwd &"') "
Set RS_insert = Application("Conn").Execute(sql_insert)
Session("message") = "THE ENTRY HAS BEEN INSERTED .. Thank You"
response.redirect "index.asp"
' 如果RS_findmember(0) 返回的值是0,就表示用户名在数据库中不存在,名字就被存入.这意味着,考生可以参答站点其它的试卷了
End If
username = replace(request.form("txt_name"),"'","''")
' 防止非法进入数据库哦.替换函数,当访问者键入了"'"单撇号,就用"''"代替

checkuser.asp

' 考生登录验证文件
sql_check = "select count(*) from loginuser where username ='" & _
username &"' and password = '" & useremail &"'"
' 验证用户名和口令是否存在于数据库中
Set RS_check = Application("Conn").Execute(sql_check)
If RS_check(0) < > 0 Then
Session("username") = request.form("username")
response.redirect "default.asp"
' 如果已注册,引导到default.asp页
End If
If RS_check(0) = 0 Then
Session("error") = "对不起,您的姓名或口令无效,请重新输入!"
response.redirect "index.asp"
' 检查用户是否已经注册,如果返回值为0,表明用户名或口令无效,回注册页
End If
username = replace(request.form("username"),"'","''")
useremail = replace(request.form("password"),"'","''")
' 替换函数

选择试卷页面default.asp。登录成功后,进入该页面。在这儿,考生可以选择的考试科目列表。在本设计中,用了001HTML 和002HTML两个,在实际应用中,可以增加表格以增加考试科目数。default.asp 要求表格安装一个下拉菜单,其中包含科目的列表,然后查询数据库,从试卷的表格中搜集两个域。

default.asp

sql_papers = "select *id, topic from paper sort order by topic asc"
SET RS_papers = Application("Conn").Execute(sql_papers)
' 以下代码是为了在下拉菜单中显示结果
SELECT size=1 name=select1 onchange="msec(document.form1._
select1.options[document.form1.select1.selectedIndex].value);" >
< option value="0" >选择科目考试
< %Do while not RS_papers.EOF% > 
< option value="< %=RS_papers("id")% >" >< %=lcase(RS_papers("topic"))% >< /OPTION >
< %
RS_papers.MoveNext 
Loop
% >
function msec(x)
' msec函数在X值的基础上调用 redirect.asp,把查询字符串: ?x的值作为下拉菜单中被选择的项的值
{if (x==0)
{ alert("欢迎参加精彩春风之精英考试,请选择一个考试科目!") 

else 
{ location.href="redirect.asp?section=" + x
}
}

终于可以参加精英赛了!

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com