资源描述
.问题描述和分工情况
1.1 问题描述
Java试卷管理系统
类型:Web应用
要求:
A. 使用JSP + Servlet+ sqlserver2005实现,Web服务器用tomcat。
B. 分为以下模块:
a) 题库管理
i. 分科目建立题库
ii. 题目包括填空题、单选题、多选题和问答题。每道题有知识点和难度。
b) 试卷管理
i. 根据题库中的题目生成试卷,随机抽题,但可以规定每个知识点所占的比例和抽取题目的各种难度所占的比例。
ii. 对生成的试卷可以人为修改。
iii. 以Word的格式输出试卷。
1.2 分工情况
邓思铭(组长):负责整个系统的需求分析,确定各功能模块,系统开发的分工及开发过程中的跟进,及整个系统的测试和调试工作;负责试题查询,试题修改等模块的实现。
李才运:负责应用程序写数据库连接,项目中登录,注册,抽取试题模板的实现。
蒋潇毅:负责数据库的设计,试题的收集,网页输出到word技术的实现。
2.系统总体设计
2.1开发环境描述
myeclipse8.5; tomcat 6.0.1; sql server 2005。
2.2 系统设计方案综述
本系统使用JSP + Servlet+ sqlserver2005实现,并通过tomcat5.0发布供外部测试及使用,系统的各主要功能流程如图1所示:
图1
3.系统详细设计
3.1 数据库设计
1) 绘制E-R图,如图2所示:
图2
2) 将E-R图转换为关系模型:
UserInfo(Unum,Utype,Uname,Upassword);
QuestionInfo(Qnum,Qcontact,Qlevel,Qtype,Qsubject,Qanswer)
3) 使用sql server 2005 创建数据库:
-----------------------创建数据库-----------------------
if exists(select * from sysdatabases where name='PaperManagerDB')
drop database PaperManagerDB
exec xp_cmdshell 'mkdir E:\accp\database\PaperManagerDB'
create database PaperDB
on(
name='PaperManagerDB_data',
filename='E:\accp\database\PaperDB\PaperManagerDB_data.mdf',
size=10,
filegrowth=1
)
log on
(
name='PaperManagerDB_log',
filename='E:\accp\database\PaperManager\PaperManagerDB_data.ldf',
size=5,
maxsize=20,
filegrowth=1
)
go
--------------------创建数据库表---------------------
/*
Qnum:试题编号
Qsubject:科目
Qtype:题型
Qcontact:内容
Qpoint:知识点
Qlevel:难度
Qanswer 答案
*/
use PaperManagerDB
go
if exists(select*from sysobjects where name='QuestionInfo')
drop table QuestionInfo
create table QuestionInfo
(
Qnum int identity(1,1) primary key,
Qsubject varchar(8) not null,
Qtype varchar(10) not null,
Qcontact text not null,
Qpoint text not null,
Qlevel varchar(10) not null,
Qanswer text not null
)
go
3.2 各模块设计
1) 数据库连接:通过编写DB类存储Web应用所用到常用数据库操作的方法,供Web调用;
代码:import java.sql.*;
public class DBConn {
Connection conn=null;
Statement state=null;
String sql="";
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=PaperManagerDB"; //连接服务器和数据库sample
String userName = "sa"; //默认用户名
String userPwd = ""; //密码
public static Connection getConnection(){
Connection conn=null;
Statement state=null;
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=PaperManagerDB";
String userName = "sa"; //默认用户名
String userPwd = ""; //密码
try {
Class.forName(driverName);
conn = DriverManager.getConnection(dbURL, userName, userPwd);
//System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void closeStatement(PreparedStatement pstate){
try{
if(pstate!=null){
pstate.close();
pstate=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
public static void closeConnection(Connection conn){
try{
if(conn !=null&&!conn.isClosed()){
conn.isClosed();
}
}catch(SQLException e){
e.printStackTrace();
}
}
public static void closeResultSet(ResultSet res){
try {
if (res!=null) {
res.close();
res=null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
2) 登录模块: 接受用户输入,通过javascript判断输入的合法性,若合法,则提交到登录页的jsp处理,通过查询数据库,判断是否存在此用户,或存在,刚进入主功能页面,并保存登录信息;
代码:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript">
function on_submit()
{
if(form1.username.value=="")
{
alert("用户名不能为空,请输入用户名!");
form1.username.focus();
return false;
}
if(form1.password.value=="")
{
alert("用户密码不能为空,请输入用户密码!");
form1.password.focus();
return false;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 36px}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="denglu1.jsp">
<table width="894" height="90" border="1">
<tr>
<th colspan="3" bgcolor="#00CC66" scope="col"><span class="STYLE1">欢迎使用试卷管理系统</span></th>
</tr>
</table>
<table width="890" height="329" border="1">
<tr>
<th width="174" height="63" scope="col"> </th>
<th width="85" scope="col"> </th>
<th width="148" scope="col"> </th>
<th width="121" scope="col"> </th>
<th width="127" scope="col"> </th>
<th width="195" scope="col"> </th>
</tr>
<tr>
<td height="49"> </td>
<td><div align="right">用户名:</div></td>
<td><input name="username" type="text" size="20" /></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="58"> </td>
<td><div align="right">用户密码:</div></td>
<td><input name="password" type="password" size="20" /></td>
<td> </td>
<td> </td>
<td><label></label></td>
</tr>
<tr>
<td height="51"> </td>
<td> <div align="right">用户类型:</div></td>
<td><label>
<input name="type" type="radio" tabindex="管理员" value="管理员" />
管理员</label></td>
<td><label>
<input type="radio" name="type" value="老师" tabindex="老师" />
老师</label></td>
<td><label>
<input name="type" type="radio" tabindex="学生" value="学生" checked="checked" />
学生</label></td>
<td><a href="zhuce.jsp">注册</a></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><label>
<input name="Submit" type="submit" tabindex="登录" value="登录" />
</label></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
3) 注册模块:接受用户输入,通过javascript判断输入的合法性,若合法,则向数据库用户表插入一条用户数据;
代码:<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {
font-family: "宋体";
font-size: 36px;
}
.STYLE2 {font-size: 36}
-->
</style>
</head>
<script language="javascript">
function on_submit()
{
if(form1.username.value=="")
{
alert("用户名不能为空!");
form1.username.focus();
return false;
}
if(form1.password.value=="")
{
alert("密码不能为空!");
form1.password.focus();
return false;
}
if(form1.checkpassword.value=="")
{
alert("确认密码不能为空!");
form1.checkpassword.focus();
return false;
}
if(form1.password.value!=form1.checkpassword.value)
{
alert("密码不一致!");
form1.checkpassword.focus();
return false;
}
if(form1.licensenum.value=="")
{
alert("用户证件号不能为空!");
form1.licensenum.focus();
return false;
}
}
</script>
<body style="">
<div id="div1" align="center"
style="height: 100px; font-family: 华文行楷; font-size: xx-large; text-decoration: blink; font-weight: bold; color: #0000FF; background-color: #CCFFCC;">
试卷管理系统
</div>
<div id="div2" style="height: 20px; background-color: #0000FF;">
</div>
<div id="div3"
style="width: 125px; background-color: #CCFF99; height: 600px;">
用户信息<br />
系统功能:<br />
<input name="Button3" type="button" id="Button" onclick="location.href='dljiemian.jsp'" value="返回" />
</div>
<div id="div4"
style="left: 139px; top: 139px; position: absolute; height: 550px; width: 750px;" >
<form action="zchoutai.jsp" method="post" name="form1" onsubmit="return on_submit()">
<table width="748" height="408" >
<tr>
<th height="65" colspan="4" scope="col"><span class="STYLE1">用户注册</span></th>
</tr>
<tr>
<td width="160"> </td>
<td width="90"> 用户名:</td>
<td width="240"><label>
<input type="text" name="username" />
</label></td>
<td width="230"> </td>
</tr>
<tr>
<td> </td>
<td>用户密码:</td>
<td><label>
<input name="password" type="password" />
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>确认密码:</td>
<td><label>
<input type="password" name="checkpassword" />
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>用户证件号:</td>
<td><label>
<input type="text" name="licensenum" />
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>用户类型:</td>
<td><span class="STYLE2">
<label>
<select name="select" size="1" class="STYLE2">
<option value="学生" selected="selected">学生</option>
<option value="老师">老师</option>
<option value="管理员">管理员</option>
</select>
</label>
</span></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><label>
<input type="submit" name="Submit" value="提交" />
</label></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</div>
</body>
</html>
4) 增加试题:接受用户输入,通过javascript判断输入的合法性,若合法,则向数据库试题表插入一条数据;
代 码:<%@ page language="java" import="java.util.*, DB.*;" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'addquestion.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form name="addquestion" method="post" action="insertQuestion.jsp">
问 题
<label>
<textarea name="contact" cols="80" rows="5" id="contact"></textarea>
</label>
<p>
<label></label>
答 案
<textarea name="answer" cols="80" rows="3" id="answer"></textarea>
</p>
<p>知识点
<label>
<input name="point" type="text" id="point" size="80">
</label>
</p>
<p>科 目
<label>
<select name="subject" id="subject">
<option value="语文">语文</option>
<option value="数学">数学</option>
<option value="英语">英语</option>
</select>
</label>
题目类型
<label>
<select name="type" id="type">
<option value="单选题">单选题</option>
<option value="多选题">单选题</option>
<option value="填空题">填空题</option>
<option value="简答题">简答题</option>
</select>
</label>
难度
<label>
<select name="level" id="level">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
<label>
<input name="reset" type="reset" id="reset" value="重填 ">
</label>
</p>
<p> </p>
</form>
<br>
</body>
</html>
5) 修改试题:接受用户输入,通过javascript判断输入的合法性,若合法,则向数据库更新或删除一条试题数据;
代码:<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@ page import=" java.util.*, DB.* ,java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
int qid;
String num="";
String page="1";
int result=0;
%>
<%
page=request.getParameter("page");
num=request.getParameter("id");
//qid=Integer.getInteger(num);
try{
String sql="delete * from QuestionInfo where Qnum=Qnum";
sql = "delete from QuestionInfo where Qnum=" + num;
Connection conn=DBConn.getConnection();
PreparedStatement pst=conn.prepareStatement(sql);
int result = pst.executeUpdate();
if(result !=1 ) {
out.println("<center>");
out.println("删除试题失败!<br><br>");
out.println("单击这里<a href=javascript:history.back()>返回</a><br>");
out.println("</center>");
}
}catch(Exception ee) {
}
%>
<jsp:forward page="showquestion.jsp">
<jsp:param name="Page" value="<%=page%>"/>
</jsp:forward>
6) 查看试题:接受用户输入查询条件,将全部符合条件的试题输入到网页中;
代码:<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%@ page import="com.tool.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'scshijuan.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<script type="text/javascript">
function on_submit()
{
if(form1.kemu.value.equals("0")
alert("请选择科目!");
if(form1.tixing.value.equals("0")
alert("请选择题型!");
if(form1.nandu.value.equals("0")
alert("请选择难度!");
}
</script>
<body>
<form id="form1" name="form1" method="post" action="zhishidian.jsp" >
<table width="893" height="154" >
<tr>
<td width="233" height="55"> </td>
<td width="102"> </td>
<td width="179"><span class="STYLE1">试题要求</span></td>
<td width="196"> </td>
<td width="149"> </td>
</tr>
<tr>
<td> </td>
<td colspan="2">科目:
<label><select name='kemu' size='1' id='kemu'>
<option value='0' selected='selected'></option>
<%
String condition="select Qsubject,count(*) from QuestInfo group by qsubject";
Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName(
展开阅读全文