基于SSH框架的在线考试系统-毕业论文 下载本文

数学与计算机科学学院毕业设计

page=\${s.subjectid}\ onclick=\window.confirm('删除科目将删除其中试题和相关成绩,是否真要删除这个科目?')\>删除


增加科目       

第${pageutil.pageno}/${pageutil.total}页       

上一页

href=\${pageutil.prepageno})\>上一页

      

下一

下一页

  

showsubject.jsp页面接收action传递过来的数据之后显示效果如下:

30

数学与计算机科学学院毕业设计

图5-7 查看试题管理效果图

到这里试题管理菜单功能已经实现,在此showsubject.jsp界面上还可以实现查看科目信息、修改科目信息、增加试题、删除科目等功能,下面列出了实现这些功能的关键代码,其具体调用过程就不再一一赘述。 1. 添加科目

// 添加科目信息

public ActionForward add(ActionMapping mapping, ActionForm form,

}

public ActionForward adddo(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) { SubjectForm sf = (SubjectForm)form; ActionForward af = null;

if(this.isTokenValid(request)) {

IQuestionService ser = BOFactory.getQuestionService(); Subject s = new Subject(); s.setIntro(sf.getIntro()); s.setName(sf.getName());

s.setSdate(Tools.d2sshort(new Date())); s.setState(sf.getState());

s.setTime(new Long(sf.getTime())); try {

ser.addSubject(s);

request.setAttribute(\,\增加科目成功\); af = mapping.findForward(\); this.resetToken(request); e.printStackTrace();

request.setAttribute(\,\增加科目失败\);

HttpServletRequest request, HttpServletResponse response) { this.saveToken(request);

SubjectForm sf = (SubjectForm)form; return mapping.findForward(\);

} catch (RuntimeException e) {

31

数学与计算机科学学院毕业设计

}

}

}

af = mapping.findForward(\);

}else {

request.setAttribute(\,\请不要重复刷新\); af = mapping.findForward(\);

return af;

2. 修改科目信息

//修改科目

public ActionForward update(ActionMapping mapping, ActionForm form,

}

public ActionForward updatedo(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) { IQuestionService ser = BOFactory.getQuestionService(); SubjectForm sf = (SubjectForm)form; try {

Subject s = ser.findSubject(sf.getSubjectid()); s.setName(sf.getName()); s.setIntro(sf.getIntro()); s.setState(sf.getState());

s.setTime(new Long(sf.getTime())); ser.updateSubject(s);

HttpServletRequest request, HttpServletResponse response) { IQuestionService ser = BOFactory.getQuestionService(); SubjectForm sf = (SubjectForm)form; try {

Subject s = ser.findSubject(sf.getSubjectid()); sf.setName(s.getName()); sf.setIntro(s.getIntro()); sf.setState(s.getState());

sf.setTime(s.getTime().intValue()); e.printStackTrace();

} catch (RuntimeException e) {

request.setAttribute(\,\查询失败\); }

return mapping.findForward(\);

request.setAttribute(\,\修改成功\); } catch (RuntimeException e) {

e.printStackTrace();

request.setAttribute(\,\修改失败\); }

return mapping.findForward(\);

32

数学与计算机科学学院毕业设计

}

3. 删除科目

// 删除科目

public ActionForward delete(ActionMapping mapping, ActionForm form,

}

HttpServletRequest request, HttpServletResponse response) { IQuestionService ser = BOFactory.getQuestionService(); SubjectForm sf = (SubjectForm)form; try {

Subject s = ser.findSubject(sf.getSubjectid()); ser.deleteSubject(s);

request.setAttribute(\,\删除成功\); } catch (RuntimeException e) {

e.printStackTrace();

request.setAttribute(\,\删除失败\); }

return mapping.findForward(\);

4. 查看试题

//查看试题

public ActionForward showquestion(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) { IQuestionService ser = BOFactory.getQuestionService(); QuestionForm sf = (QuestionForm)form;

String spageno = request.getParameter(\); try {

Subject s = ser.findSubject(sf.getSubjectid());

int num = ser.findQuestionnumBySubjects(sf.getSubjectid()); PageUtil pu = new PageUtil(spageno,num,Constant.PAGESIZE); List list =

ser.findQuestionBySubjects(sf.getSubjectid(),pu.getPageno(),pu.getPagesize());

}

request.setAttribute(\,list); request.setAttribute(\,pu); request.setAttribute(\,s); e.printStackTrace();

} catch (RuntimeException e) {

request.setAttribute(\,\查询失败\); }

return mapping.findForward(\);

5. 添加试题

//添加试题

public ActionForward addquestion(ActionMapping mapping, ActionForm form,

33