《在线考试系统实现论文.doc》由会员分享,可在线阅读,更多相关《在线考试系统实现论文.doc(29页珍藏版)》请在三一办公上搜索。
1、远东在线考试系统简述1. 功能概述2. 需求分析3. 数据库设计4. 考试系统预览5. 项目难点分析与解决方案6. 项目优势与特色一功能概述本考试系统是真正的零安装、; 全B/S架构的在线考试系统、网上自测和模拟考试平台,易学易用; 采用最新Web2.0技术和Ajax技术,强调与用户的交互,更加人性化; 提供了市面上考试系统里最全面的试卷支持:采用独创与全面革新性的“所见即所得”的在线试卷录入技术, 支持单选题、判断题、填空题、图片题; 支持录入各种文字、图片和表格内容,就跟在WORD里编辑一样的; 支持系统自评分 可以匿名练习,练习结束自动评分,练习期间也可以查看正确答案,自动判错,查看答题
2、情况。 可以注册登录后考试,自动保存答卷和成绩供随时查阅;可以进行统一地考试、阅卷和成绩管理等; 自动临时保存机制可以有效防止意外断电、死机造成的考试中断; 以树形结构来管理所有科目,以科目为单位来管理试卷和考试,极大的方便用户使用。 。 支持在电脑教室、培训室、企事业单位内部网络上实现真正的统一考试模式; 可以完成分发试卷、集中监考、学生交卷或强制收卷、防舞弊等一系列的考试流程;老师也可以集中阅卷、查看所有学生的答卷和成绩; 支持禁止窗口切换、试题选项随机顺序等防舞弊机制。功能概述 全功能的在线考试系统本在线考试系统是针对各类学校设计的新一代纯B/S架构的在线考试系统,它支持帐户管理、班级管
3、理、科目管理、试卷录入管理,支持网上自测和模拟考试/作业练习/考核测评/班级统一考试等不同的考试需求,支持系统自评分,成绩查阅、成绩管理等、防舞弊等一系列的考试流程。 系统架构 新一代纯B/S架构的在线考试系统本系统属于纯B/S架构,无需安装任何客户端,学生用户通过浏览器登录系统,参加考试、完成作业或练习、查看考试成绩等;教师用户通过浏览器登录系统,进行学生管理、班级管理、完成试卷录入、组织班级统一考试、集中处理阅卷和成绩管理等。二需求分析1 学生注册和登录(可以上传个人头像)2 学生在线练习3 学生在线考试(增加故障保护完全保障开始的正常进行)4 考试和练习在线判卷5 后台管理(对整个数据库
4、信息的管理)6 学生管理7 试卷管理8 成绩管理9 管理员信息管理(增加了信息搜索功能和试卷自动生成功能)ems后台设计分析文挡采用了工厂设计模式:如图添加时序图:如图运用动态代理统一处理事务transaction如图:(1)学生在线考试流程(2)管理员管理流程三数据库设计Adminstrator表设计:Exampaper表设计:Messageprotect表设计:Score表设计:Student表的设计:Score视图的设计:四考试系统预览登录界面个人信息试卷选择页面练习页面吗考试页面注册页面管理员登录首页管理页面五项目难点分析与解决方案1. 登录实现的javabean代码package c
5、om.fe.ems.util;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;public class Login String s_password;String id;String s_name;boolean examstates = true;/答题状态,为true时允许进入答题页面,否则不准进入。boolean b = true; /在updatePhoto.jsp页面用来控制框架reload。为tru
6、e时reload,为false时禁止reload。boolean success = false; /用户登陆状态变量boolean adminSuccess = false;/管理员登陆状态变量String backNews = ;/反馈用户登陆信息StringBuffer sb = new StringBuffer();/String adminBackNews = ;/反馈管理员登录信息public String handleString(String s)trybyte bb = s.getBytes(gbk);s = new String(bb);catch(Exception e)
7、return s;此处省去了get()和set()方法。public void login(String sid,String spassword)/返回真登陆成功,返回假登陆失败/if(!success)if(true)if(true)Connection conn = null;PreparedStatement sql = null;ResultSet rs = null;try conn = DB.getConnection();boolean boo = (sid = ? false:true) & (spassword = ? false:true);/ 判断密码是否为空Strin
8、g condition = select * from student where s_id=?;sql = conn.prepareStatement(condition);if(boo)sql.setString(1, sid);rs = sql.executeQuery();boolean m = false;rs.next();if(rs.getString(s_password).equals(spassword)m = true;if(m = true)this.id = sid;this.s_password = spassword;s_name = rs.getString(s
9、_name);backNews = 登陆成功;success = true;elsebackNews = formatIndex + 您输入的用户名不存在,或密码不匹配;success = false;elsebackNews = formatIndex + 您输入的用户名或密码为空。;success = false; catch (SQLException e) /System.out.println(e);success = false;backNews = formatIndex + 您输入的用户名或密码错误!;catch(Exception e)backNews = formatInd
10、ex + 您输入的用户名或密码错误!;finally DB.close(rs);DB.close(sql);DB.close(conn); 2. 登录成功后用javascript实现动态跳转代码function divMessageBox(title, msg, w, h) var showTime= 2000;var t = showTime/1000;var titleheight = 22px; / 提示窗口标题高度 var bordercolor = #278BBB; / 提示窗口的边框颜色 var titlecolor = #FFFFFF; / 提示窗口的标题颜色 var title
11、bgcolor = #4CD7F1; / 提示窗口的标题背景色var bgcolor = #0195C2; / 提示内容的背景色var iWidth = document.documentElement.clientWidth; var iHeight = document.documentElement.clientHeight; var bgObj = document.createElement(div); bgObj.style.cssText = position:absolute;left:0px;top:0px;width:+iWidth+px;height:+Math.max(
12、document.body.clientHeight, iHeight)+px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:101;document.body.appendChild(bgObj); http:var msgObj=document.createElement(div);msgObj.style.cssText = position:absolute;font:11px 宋体;top:+(iHeight-h + 200)/2+px;left:+(iWidth-w+ 240) /2+p
13、x;width:+w+px;height:+h+px;text-align:center;border:1px solid +bordercolor+;background-color:+bgcolor+;padding:1px;line-height:22px;z-index:102;document.body.appendChild(msgObj);var table = document.createElement(table);msgObj.appendChild(table);table.style.cssText = margin:0px;border:0px;padding:0p
14、x;table.cellSpacing = 0;var tr = table.insertRow(-1);var titleBar = tr.insertCell(-1);titleBar.style.cssText = width:100%;height:+titleheight+px;text-align:left;padding:3px;margin:0px;font:bold 13px 宋体;color:+titlecolor+;border:1px solid + bordercolor + ;cursor:move;background-color: + titlebgcolor;
15、titleBar.style.paddingLeft = 10px;titleBar.innerHTML = title;var moveX = 200;var moveY = 300;var moveTop = 200;var moveLeft = 300;var moveable = false;var docMouseMoveEvent = document.onmousemove;var docMouseUpEvent = document.onmouseup;titleBar.onmousedown = function() var evt = getEvent(); moveabl
16、e = true; moveX = evt.clientX; moveY = evt.clientY; moveTop = parseInt(msgObj.style.top); moveLeft = parseInt(msgObj.style.left); document.onmousemove = function() if (moveable) var evt = getEvent(); var x = moveLeft + evt.clientX - moveX; var y = moveTop + evt.clientY - moveY; if ( x 0 &( x + w 0 &
17、 (y + h iHeight) ) msgObj.style.left = x + px; msgObj.style.top = y + px; ; document.onmouseup = function () if (moveable) document.onmousemove = docMouseMoveEvent; document.onmouseup = docMouseUpEvent; moveable = false; moveX = 0; moveY = 0; moveTop = 0; moveLeft = 0; ;var closeBtn = tr.insertCell(
18、-1);closeBtn.style.cssText = cursor:pointer; padding:2px;background-color: + titlebgcolor;closeBtn.innerHTML = ;closeBtn.onclick = divMessagesClose;var msgBox = table.insertRow(-1).insertCell(-1);msgBox.style.cssText = font:12pt 宋体;height:50px;msgBox.colSpan = 3;msgBox.innerHTML = msg;/显示剩余的时间数var t
19、ime = table.insertRow(-1).insertCell(-1);time.style.cssText = font:9pt 宋体;time.innerHTML = t+ 秒后自动跳转!;/ 获得事件Event对象,用于兼容IE和FireFox function getEvent() return window.event | arguments.callee.caller.arguments0; /处理自动关闭事件function autoClose() -t;if(t0) time.innerHTML = t+ 秒后自动跳转!; setTimeout(autoClose,1
20、000);else setTimeout(divMessagesClose,1000); /跳转的页面! location = student/index.jsp; /关闭function divMessagesClose() document.body.removeChild(bgObj); document.body.removeChild(msgObj); /处理入口setTimeout(autoClose,1000); 3图片上传到服务器package com.fe.ems.util;import java.io.IOException;import java.io.PrintWrit
21、er;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import mons.fileupload.*;import java.util.*;import java.util.regex.*;import java.io.*;import mons.fileupload.servlet.*;import mons
22、.fileupload.disk.DiskFileItemFactory;/* * 创建日期 2005-4-10 * * TODO 要更改此生成的文件的模板,请转至 * 窗口 首选项 Java 代码样式 代码模板 */* * author gaolong1 * * TODO 要更改此生成的类型注释的模板,请转至 窗口 首选项 Java 代码样式 代码模板 */public class FileUpload extends HttpServlet /* * Destruction of the servlet. */private String uploadPath = ; / 用于存放上传文件
23、的目录private File tempPath = new File(D:addnetFiletmp); / 用于存放临时文件的目录public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to * post. * * param request * t
24、he request send by the client to the server * param response * the response send by the server to the client * throws ServletException * if an error occurred * throws IOException * if an error occurred */public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOEx
25、ception res.setContentType(text/html; charset=GB2312);PrintWriter out = res.getWriter();System.out.println(req.getContentLength();System.out.println(req.getContentType();DiskFileItemFactory factory = new DiskFileItemFactory();/ maximum size that will be stored in memoryfactory.setSizeThreshold(4096)
26、;/ the location for saving data that is larger than getSizeThreshold()factory.setRepository(new File(d:FileaddnetFiletemp);ServletFileUpload upload = new ServletFileUpload(factory);/ maximum size before a FileUploadException will be thrownupload.setSizeMax(1000000);String sId = ;try List fileItems =
27、 upload.parseRequest(req);/ assume we know there are two files. The first file is a small/ text file, the second is unknown and is written to a file on/ the serverIterator iter = fileItems.iterator();/ 正则匹配,过滤路径取文件名String regExp = (.+)$;/ 过滤掉的文件类型String errorType = .exe, .com, .cgi, .asp ;Pattern p
28、= Ppile(regExp);while (iter.hasNext() FileItem item = (FileItem) iter.next();if (item.isFormField() if (sId.equals(item.getFieldName() sId = item.getString();/ 忽略其他不是文件域的所有表单信息if (!item.isFormField() String name = item.getName();name = name.substring(name.lastIndexOf()+1);long size = item.getSize();
29、if (name = null | name.equals() & size = 0)continue;Matcher m = p.matcher(name);boolean result = m.find();if (result) for (int temp = 0; temp errorType.length; temp+) if (m.group(1).endsWith(errorTypetemp) throw new IOException(name + : wrong type);try String temp = req.getSession().getServletContex
30、t().getRealPath(images/item);System.out.println(temp= + temp);/ 保存上传的文件到指定的目录/ 在下文中上传文件至数据库时,将对这里改写item.write(new File(uploadPath + sId + .jpg);out.print(name + + size + );res.sendRedirect(req.getContextPath() + /student/iframe_update.jsp); catch (Exception e) out.println(e); else throw
31、 new IOException(fail to upload); catch (IOException e) out.println(e); catch (FileUploadException e) out.println(e);/ 保存上传的文件到指定的目录/ 在下文中上传文件至数据库时,将对这里改写/* * Initialization of the servlet. * * throws ServletException * if an error occure */public void init() throws ServletException this.uploadPath
32、= this.getServletConfig().getInitParameter(upload_path);/public void init(ServletConfig config) throws ServletException /super.init(config);/this.uploadPath = config.getInitParameter(upload-path);/4考试页面随机出题实现代码将数据库中的试题题号存放在一个数组里,然后将数组里的值随机交换。 for ( var i= ; i = 0 ; i- ) /alert(i); var v = parseInt(M
33、ath.random()*(i+1); var tmp = timuIdv; timuIdv = timuIdi; timuIdi = tmp; 5 在线考试系统最大的难点就是考试期间的异常,如突然断电,电脑死机等等事件。对于考试的稳定性来说是非常致命的。解决对策用户每做三个题或是两个题就向protectMessage表中存一次数据,将用户的答案和剩余时间存到表中。当异常发生时,用户再次登录,将进行信息验证,把表中的剩余时间和答案反馈到用户考试界面。确保了考试的正常进行。int questioncount = 0; /用来控制保存答案的频率/每答完3个题保存一次if(questioncount
34、 = 2)examtime.setTimeLeft(seconds,Login.getId(),examtime.getP_id();examtime.setAnswer(str,Login.getId(),examtime.getP_id();questioncount = 0;elsequestioncount +;用到javabean中的方法public String getTimeLeft(String id,String p_id)String time = ;String sql = select timeout from messageprotect where s_id=? a
35、nd p_id=?;Connection conn = null;PreparedStatement pstmt = null;ResultSet rs = null;PaperModel paper = null;try conn = DB.getConnection();pstmt = conn.prepareStatement(sql);pstmt.setString(1, id);pstmt.setString(2, p_id);rs = pstmt.executeQuery();if (rs.next() time = rs.getString(1);elsecatch(SQLExc
36、eption e) e.printStackTrace();finally DB.close(rs);DB.close(pstmt);DB.close(conn); return time;/* * 设置用户答题剩余时间 * param timeout * param id */public void setTimeLeft(int timeout,String id,String p_id)Connection conn = null;PreparedStatement pstmt = null;try conn = DB.getConnection();String condition =
37、 update messageprotect set timeout=? where s_id=? and p_id=?;pstmt = conn.prepareStatement(condition);pstmt.setInt(1, timeout);pstmt.setString(2, id);pstmt.setString(3, p_id);pstmt.executeUpdate(); catch (SQLException e) e.printStackTrace();finally DB.close(pstmt);DB.close(conn);/* * 获取用户答案。 * param
38、 id * return */public String getAnswer(String id,String p_id)String time = ;String sql = select answer from messageprotect where s_id=? and p_id=?;Connection conn = null;PreparedStatement pstmt = null;ResultSet rs = null;PaperModel paper = null;try conn = DB.getConnection();pstmt = conn.prepareStatement(sql);pstmt.setString(1, id);pstmt.setString(2, p_id);rs = pstmt.executeQuery();if (rs.next() time = rs.getString(1);elsecatch(SQLExcepti