JAVA课程设计
一、团队介绍
学号
班级
姓名
分工
201721123077
网络1713
张荣波
后端
201721123078
网络1713
康黎彬
数据库、博客
201721123080
网络1713
郭胤鑫
后端
201721123092
网络1713
雷晨晖
前端,UI
二、项目git地址
https://gitee.com/ZhangRongBo/online_examination_system
三、项目git提交记录截图
四、项目结构功能图与主要功能结构图
项目结构功能图:
主要功能结构图:
五、项目运行截图
1.学生登录界面
2.学生注册
3.考试界面
4.成绩查询
5.修改资料
6.管理员登录界面
7.后台管理部分界面
六、项目关键代码
publicLesson() {this.lessonDAO = newLessonDAO();
}publicActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String action= request.getParameter("action");
System.out.println("获取的查询字符串:" +action);if (action == null || "".equals(action)) {return mapping.findForward("error");
}else if ("lessonQuery".equals(action)) {returnlessonQuery(mapping, form, request, response);
}else if ("lessonAdd".equals(action)) {returnlessonAdd(mapping, form, request, response);
}else if ("lessonDel".equals(action)) {returnlessonDel(mapping, form, request, response);
}else if("selectLesson".equals(action)){returnselectLesson(mapping, form, request, response);
}else if("ready".equals(action)){returnready(mapping, form, request, response);
}
request.setAttribute("error", "操作失败!");return mapping.findForward("error");
}
privateActionForward submitTestPaper(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
QuestionsForm q=(QuestionsForm)form;
String rightAnswer="";float singleMark=0;float moreMark=0;
String[] single=q.getAnswerArrS();int[] singleId=q.getIdArrS();//System.out.println(q.getID());
System.out.println("数据的长度:"+single.length);float markS=40/(single.length);for(int i=0;i
rightAnswer=startExamDAO.getRightAnswer(singleId[i]);
System.out.println("单选数组:"+i+"********ID号"+singleId[i]+"********"+single[i]+"****正确答案"+rightAnswer);if(rightAnswer.equals(single[i])){
singleMark=singleMark+markS; //累加单选题的分数
}
}
System.out.println("单选题得分:"+singleMark);
MoreSelect[] more=q.getMoreSelect();
System.out.println("多选数组的长度:"+more.length);float markM=60/(more.length);
String str="";for(int i=0;i
String[] ans=more[i].getAnswerArr();int[] moreId=q.getIdArrM();
rightAnswer=startExamDAO.getRightAnswer(moreId[i]);
System.out.println("多选数组:"+i+"********ID号"+moreId[i]+"********"+more[i]+"****正确答案"+rightAnswer);for(int j=0;j
}if(str.length()>1){
str=str.substring(0,str.length()-1);
}
System.out.println("获取的多选题答案:"+str);if(rightAnswer.equals(str)){
moreMark=moreMark+markM; //累加多选题的分数
}
str="";
}
System.out.println("多选题得分:"+moreMark);
HttpSession session=request.getSession();
String student=session.getAttribute("student").toString();int lessonID=Integer.parseInt(session.getAttribute("lessonID").toString()); //课程ID
int ret=startExamDAO.saveResult(student,lessonID,(int)Math.round(singleMark),(int)Math.round(moreMark));if(ret>0){
request.setAttribute("submitTestPaperok", "试卷已提交,您本次考试的成绩为:"+(Math.round(singleMark)+Math.round(moreMark))+"分!");return mapping.findForward("submitTestPaperok");
}else{return mapping.findForward("dealNull");
}
}
}
//找回密码(第一步)
privateActionForward seekPwd1(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
StudentForm studentForm=(StudentForm) form;
StudentForm s=studentDAO.seekPwd1(studentForm);
request.setAttribute("seekPwd2", s);if(s.getID().equals("")){
request.setAttribute("error", "您输入的准考证号不存在!");return mapping.findForward("error");
}else{return mapping.findForward("seekPwd1");
}
}//找回密码(第二步)
privateActionForward seekPwd2(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
StudentForm studentForm=(StudentForm) form;
StudentForm s=studentDAO.seekPwd2(studentForm);
request.setAttribute("seekPwd3", s);if(s.getID().equals("")){
request.setAttribute("error", "您输入的密码提示问题的答案不正确!");return mapping.findForward("error");
}else{return mapping.findForward("seekPwd2");
}
}
publicResultSet executeQuery(String sql) {try { //捕捉异常
conn = getConnection(); //调用getConnection()方法构造Connection对象的一个实例conn
stmt =conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException ex) {
System.err.println(ex.getMessage());//输出异常信息
}return rs; //返回结果集对象
}public intexecuteUpdate(String sql) {int result = 0; //定义保存返回值的变量
try { //捕捉异常
conn = getConnection(); //调用getConnection()方法构造Connection对象的一个实例conn
stmt =conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result= stmt.executeUpdate(sql); //执行更新操作
} catch(SQLException ex) {
result= 0; //将保存返回值的变量赋值为0
}return result; //返回保存返回值的变量
}
[ ${ind+1} ]
A.
B.
C.
D.
主要截取了一些诸如执行action的代码,以及前端传入form实例类的代码,以及DAO模式的存贮代码和返回后端的代码。
七、项目代码扫描结果及改正
扫描结果:
改正:
八、尚待改进
前端设计的时候并不是使用的动态化设计,并且在设计前端内容的时候没有考虑到整个去应用模块化设计,增加了后续的迭代难度。
后端中实例类的底层架构不够完美,在后续的开发工作中遇到了之前未想到的问题。归根结底是对面向对象编程的不熟悉,对类中属性和类承担的责任的不严谨导致后续迭代产生了困难。最后导致注入单选多选必须同时存在的问题。
部分功能无法实现:学生类中缺少相应的属性,使得管理员不得指定一个学生只能参加特定的考试,或者让该学生补考。