最近在做课设,抽到的题目是《基于jsp+MySQL的在线考试系统》,拿到这个题目后,我做了如下规划,怎么去实现一个在线考试系统:
1、注册 (学生)注册信息包括登录帐号、姓名、性别、年龄、班级、任课老师。 2、参加考试 (学生)从试卷列表中选择考试卷,考试卷由管理人员(一般由老师担任)创建。试卷信息包括试卷ID(生成规则后面在"试卷管理"用例中描述)、试卷科目、满分、时间、试卷有效期。 3、试卷管理:(管理人员) 试卷主体信息维护(创建试卷、修改试卷相关信息、删除试卷)。 4、题库管理:(管理人员)题目信息维护(创建题目、修改题目、删除题目)。
基本架构有后,参考了网上一些项目的源码,写下了这个系统,以下是部分代码:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <jsp:useBean id="lesson" class="com.wgh.dao.TaoTiDAO" scope="page"/> <% int lessonID=Integer.parseInt((String)session.getAttribute("lessonID")); List list_s=(List)request.getAttribute("singleQue"); int s=40/list_s.size(); List list_m=(List)request.getAttribute("moreQue"); int m=60/list_m.size(); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>网络在线考试</title> <link rel="stylesheet" href="../CSS/style.css"/> <script language="javascript" src="../JS/AjaxRequest.js"> </script> <script language="javascript"> timer = window.setInterval("showStartTime();showRemainTime();",1000); //此处需要加&nocache="+new Date().getTime(),否则将出现时间不自动走动的情况 function showStartTime(){ var loader=new net.AjaxRequest("startExam.do?action=showStartTime&nocache="+new Date().getTime(),deal_s,onerror,"GET"); } function showRemainTime(){ var loader1=new net.AjaxRequest("startExam.do?action=showRemainTime&nocache="+new Date().getTime(),deal_r,onerror,"GET"); } function onerror(){ window.open('../index.jsp','','toolbar,menubar,scrollbars,resizable,status,location,directories,copyhistory,height=600,width=778'); window.close(); } function deal_s(){ showStartTimediv.innerHTML=this.req.responseText; } function deal_r(){ showRemainTimediv.innerHTML=this.req.responseText; if(this.req.responseText=="00:00:00"){ questionsForm.submit.click(); } } </script> <script language=javascript> function keydown(){ if(event.keyCode==8){ event.keyCode=0; event.returnValue=false; alert("当前设置不允许使用退格键"); }if(event.keyCode==13){ event.keyCode=0; event.returnValue=false; alert("当前设置不允许使用回车键"); }if(event.keyCode==116){ event.keyCode=0; event.returnValue=false; alert("当前设置不允许使用F5刷新键"); }if((event.altKey)&&((window.event.keyCode==37)||(window.event.keyCode==39))){ event.returnValue=false; alert("当前设置不允许使用Alt+方向键←或方向键→"); }if((event.ctrlKey)&&(event.keyCode==78)){ event.returnValue=false; alert("当前设置不允许使用Ctrl+n新建IE窗口"); }if((event.shiftKey)&&(event.keyCode==121)){ event.returnValue=false; alert("当前设置不允许使用shift+F10"); } } function click() { event.returnValue=false; alert("当前设置不允许使用右键!"); } document.oncontextmenu=click; </script> </head> <body onLoad="showStartTime();showRemainTime();" onkeydown="keydown()"> <table width="770" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"> <tr> <td width="40" height="39" background="../Images/startExam_leftTop.jpg"> </td> <td width="667" align="right" background="../Images/startExam_top.jpg"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="23%" nowrap height=23 align=right>考试时间:</td> <td width="14%" nowrap><font color="#FF0000">20</font>分钟</td> <td width="13%" nowrap>计 时:</td> <td width="60" nowrap><div id="showStartTimediv">00:00:00</div> </td> <td width="16%" nowrap>剩余时间:</td> <td width="60" align=left nowrap><div id="showRemainTimediv"></div></td></tr> </table> </td> <td width="19" background="../Images/startExam_top.jpg"> </td> <td width="44" background="../Images/startExam_rightTop.jpg"> </td> </tr> <tr> <td height="435" rowspan="2" background="../Images/startExam_left.jpg"> </td> <td height="43" colspan="2"><img src="../Images/startExam_ico.jpg" width="117" height="43"></td> <td rowspan="2" background="Images/startExam_right.jpg"> </td> </tr> <tr> <td height="600" colspan="2" valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2" align="center" class="title"><%=lesson.getLesson(lessonID)%> 考试卷 </td> </tr> <tr> <td width="64%"> </td> <td width="36%"> 满分<font color="red">100</font>分 单选题<font color="red">40</font>分 多选题<font color="red">60</font>分</td> </tr> </table> <html:form action="/startExam.do?action=submitTestPaper" method="post"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td> <table id="single" width="90%" border="0" cellspacing="0" cellpadding="0" align=center> <tr> <td colspan="4" height=23 style="font-size:11pt;">一、单选题(<font color=red>每题<%=s %>分,答错不得分</font>)</td> </tr> <logic:iterate id="questions" name="singleQue" type="com.wgh.actionForm.QuestionsForm" scope="request" indexId="ind"> <tr> <td height=23 colspan="4" align=center nowrap> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="8%" align=right height=23>[ ${ind+1} ]</td> <td width="2%"> </td> <td width="90%" align=left nowrap style="font-size:11pt;"><bean:write name="questions" property="subject" filter="true"/> <html:hidden property="idArrS[${ind}]" name="questions"/> </td> </tr> </table> </td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="A"/></td> <td width="3%" align=center nowrap>A.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionA" filter="true"/></td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="B"/></td> <td width="3%" align=center nowrap>B.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionB" filter="true"/></td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="C"/></td> <td width="3%" align=center nowrap>C.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionC" filter="true"/></td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:radio property="answerArrS[${ind}]" styleClass="noborder" value="D"/></td> <td width="3%" align=center nowrap>D.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionD" filter="true"/></td> </tr> </logic:iterate> </table> <table id="single" width="90%" border="0" cellspacing="0" cellpadding="0" align=center> <tr> <td colspan="4" height=23 style="font-size:11pt;">二、多选题(<font color=red>每题<%=m%>分,答错不得分</font>)</td> </tr> <logic:iterate id="questions" name="moreQue" type="com.wgh.actionForm.QuestionsForm" scope="request" indexId="ind"> <tr> <td height=23 colspan="4" align=center nowrap> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="8%" align=right height=23>[ ${ind+1} ]</td> <td width="2%"> </td> <td width="90%" align=left nowrap style="font-size:11pt;"><bean:write name="questions" property="subject" filter="true"/> <html:hidden property="idArrM[${ind}]" name="questions"/> </td> </tr> </table> </td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:multibox property="moreSelect[${ind}].answerArr" styleClass="noborder" value="A"/></td> <td width="3%" align=center nowrap>A.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionA" filter="true"/></td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:multibox property="moreSelect[${ind}].answerArr" styleClass="noborder" value="B"/></td> <td width="3%" align=center nowrap>B.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionB" filter="true"/></td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:multibox property="moreSelect[${ind}].answerArr" styleClass="noborder" value="C"/></td> <td width="3%" align=center nowrap>C.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionC" filter="true"/></td> </tr> <tr> <td width="8%" height=23 nowrap> </td> <td width="3%" align=center nowrap><html:multibox property="moreSelect[${ind}].answerArr" styleClass="noborder" value="D"/></td> <td width="3%" align=center nowrap>D.</td> <td width="86%" align=left nowrap><bean:write name="questions" property="optionD" filter="true"/></td> </tr> </logic:iterate> </table> </td> </tr> <tr> <td align="center"><html:submit property="submit" styleClass="btn_grey" value="交卷"/> </td> </tr> </table> </html:form> </td> </tr> <tr> <td width="40" height="40" background="../Images/startExam_leftBottom.jpg"> </td> <td colspan="2" background="../Images/startExam_bottom.jpg"> </td> <td background="../Images/startExam_rightBottom.jpg"> </td> </tr> </table> </body> </html> /* SQLyog 企业版 - MySQL GUI v8.14 MySQL - 5.1.49-community : Database - db_exam ********************************************************************* */ /*!40101 SET NAMES utf8 */; /*!40101 SET SQL_MODE=''*/; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; CREATE DATABASE /*!32312 IF NOT EXISTS*/`db_exam` /*!40100 DEFAULT CHARACTER SET utf8 */; USE `db_exam`; /*Table structure for table `tb_lesson` */ DROP TABLE IF EXISTS `tb_lesson`; CREATE TABLE `tb_lesson` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(60) DEFAULT NULL, `JoinTime` datetime DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8; /*Data for the table `tb_lesson` */ insert into `tb_lesson`(`ID`,`Name`,`JoinTime`) values (4,'英语(二)','2019-01-01 00:00:00'),(5,'计算机文化基础','2019-01-01 00:00:00'),(8,'计算机专业英语','2019-01-01 00:00:00'),(29,'电子商务','2019-01-01 00:00:00'),(31,'数学','2019-01-01 00:00:00'),(33,'12','2019-08-02 10:29:10'); /*Table structure for table `tb_manager` */ DROP TABLE IF EXISTS `tb_manager`; CREATE TABLE `tb_manager` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) DEFAULT NULL, `PWD` varchar(30) DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8; /*Data for the table `tb_manager` */ insert into `tb_manager`(`ID`,`name`,`PWD`) values (4,'tsoft','111'),(14,'00','000000'); /*Table structure for table `tb_questions` */ DROP TABLE IF EXISTS `tb_questions`; CREATE TABLE `tb_questions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `subject` varchar(50) DEFAULT NULL, `type` char(6) DEFAULT NULL, `joinTime` datetime DEFAULT NULL, `lessonId` int(11) DEFAULT NULL, `taoTiId` int(11) DEFAULT NULL, `optionA` varchar(50) DEFAULT NULL, `optionB` varchar(50) DEFAULT NULL, `optionC` varchar(50) DEFAULT NULL, `optionD` varchar(50) DEFAULT NULL, `answer` varchar(10) DEFAULT NULL, `note` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8; /*Data for the table `tb_questions` */ insert into `tb_questions`(`id`,`subject`,`type`,`joinTime`,`lessonId`,`taoTiId`,`optionA`,`optionB`,`optionC`,`optionD`,`answer`,`note`) values (37,'Windows 2000是什么?','单选题','2013-01-01 00:00:00',5,10,'应用软件','操作系统','应用程序','以上都不是','B','空'),(39,'网络营销的发展经历几个阶段?','单选题','2013-01-01 00:00:00',29,17,'2个','3个','5个','6个','C','空'),(40,'Internet提供的基本服务有哪些?','多选题','2013-01-01 00:00:00',29,17,'E-mail','FTP','Telnet','WWW','A,B,C,D','空'),(48,'EPROM代表什么?','单选题','2013-01-01 00:00:00',8,19,'可编程存储器','可擦可编程存储器','只读存储器','可擦可编程只读存储器','D',''),(49,'对于WWW的正确解释有哪些?','多选题','2013-01-01 00:00:00',8,19,'全球网','万维网','局域网','World Wide Web的缩写','A,B,D',''),(50,'5*5','单选题','2013-01-01 00:00:00',31,20,'20','30','25','50','C','无'),(51,'下列数据属于整数的是?','多选题','2013-01-01 00:00:00',31,20,'1','2','3','4','A,B,C,D','无'); /*Table structure for table `tb_student` */ DROP TABLE IF EXISTS `tb_student`; CREATE TABLE `tb_student` ( `ID` varchar(16) DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `pwd` varchar(20) DEFAULT NULL, `sex` varchar(2) DEFAULT NULL, `joinTime` datetime DEFAULT NULL, `question` varchar(50) DEFAULT NULL, `answer` varchar(50) DEFAULT NULL, `profession` varchar(30) DEFAULT NULL, `cardNo` varchar(18) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*Data for the table `tb_student` */ insert into `tb_student`(`ID`,`name`,`pwd`,`sex`,`joinTime`,`question`,`answer`,`profession`,`cardNo`) values ('CN20071201000001','王*晶','111','女','2013-01-01 00:00:00','birthday','717','广告学','220198302********'),('CN20071201000002','无语','111','女','2013-01-01 00:00:00','birthday','1','计算机应用软件','220198007********'),('CN20071225000005','无语','111111','女','2013-01-01 00:00:00','我最喜欢的颜色','蓝灰色','计算机应用软件','220104************'),('CN20071229000006','明明','000','女','2013-01-01 00:00:00','你好','你好','公司管理','20020'),('CN20071229000007','丽丽','111111','女','2013-01-01 00:00:00','你好','你好','编程','52200'); /*Table structure for table `tb_sturesult` */ DROP TABLE IF EXISTS `tb_sturesult`; CREATE TABLE `tb_sturesult` ( `id` int(11) NOT NULL AUTO_INCREMENT, `stuId` varchar(16) DEFAULT NULL, `whichLesson` varchar(60) DEFAULT NULL, `resSingle` int(11) DEFAULT NULL, `resMore` int(11) DEFAULT NULL, `resTotal` int(11) DEFAULT NULL, `joinTime` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8; /*Data for the table `tb_sturesult` */ insert into `tb_sturesult`(`id`,`stuId`,`whichLesson`,`resSingle`,`resMore`,`resTotal`,`joinTime`) values (1,'CN20071201000002','计算机专业英语',50,30,80,'2013-01-01 00:00:00'),(2,'CN20071201000001','计算机文化基础',0,20,20,'2013-01-01 00:00:00'),(4,'CN20071201000001','电子商务',20,30,50,'2013-01-01 00:00:00'),(12,'CN20071201000001','计算机专业英语',40,60,100,'2013-01-01 00:00:00'),(14,'CN20071225000005','计算机文化基础',40,0,40,'2013-01-01 00:00:00'),(29,'CN20071201000002','计算机文化基础',40,60,100,'2013-01-01 00:00:00'),(30,'CN20071229000006','数学',40,60,100,'2013-01-01 00:00:00'),(37,'CN20071229000007','计算机专业英语',0,0,0,'2013-01-01 00:00:00'),(38,'CN20071229000007','数学',40,60,100,'2013-01-01 00:00:00'),(39,'CN20071229000006','电子商务',0,0,0,'2013-01-01 00:00:00'),(40,'CN20071201000001','数学',0,0,NULL,NULL),(41,'CN20071201000002','电子商务',0,0,NULL,'2013-08-02 11:43:15'),(42,'CN20071201000002','数学',40,0,40,'2013-08-02 13:10:12'); /*Table structure for table `tb_taoti` */ DROP TABLE IF EXISTS `tb_taoti`; CREATE TABLE `tb_taoti` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(50) DEFAULT NULL, `LessonID` int(11) DEFAULT NULL, `JoinTime` datetime DEFAULT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8; /*Data for the table `tb_taoti` */ insert into `tb_taoti`(`ID`,`Name`,`LessonID`,`JoinTime`) values (10,'2007年期末考试',5,'2013-01-01 00:00:00'),(17,'2007年上半年期中考试题',29,'2013-01-01 00:00:00'),(19,'2007年期末考试题A',8,'2013-01-01 00:00:00'),(20,'大学数学',31,'2013-01-01 00:00:00'); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;这中间遇到很多问题,比如配置文件中.do文件的执行时由于与action中所写url不同导致数据库的读取失败等等,这些最终都解决了,以下是界面图:
需要源码(jsp+Mysql)的联系我,联系QQ:1319489213。有什么问题可以咨询我,共同学习。