java网络考试系统

功能:可进行学生、管理员登录,学生考试、管理员出卷、列表分页

@

实现效果





主要代码实现

package cn.itbaizhan.tyut.exam.sys.servlets;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import cn.itbaizhan.tyut.exam.common.PageControl;
import cn.itbaizhan.tyut.exam.common.Pager;
import cn.itbaizhan.tyut.exam.common.Tools;
import cn.itbaizhan.tyut.exam.model.SysFunction;
import cn.itbaizhan.tyut.exam.sys.services.impl.FunService;
import cn.itbaizhan.tyut.exam.sys.services.interfaces.IFunService; public class FunServlet extends HttpServlet { IFunService service = new FunService();
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String cmd = request.getParameter("cmd");
if(cmd.equals("add")){
addfun(request,response);
}else if(cmd.equals("list")){
funlist(request,response);
}else if(cmd.equals("toedit")){
toedit(request,response);
}else if(cmd.equals("edit")){
edit(request,response);
}
} /**
* 修改系统功能
* @param request
* @param response
*/
private void edit(HttpServletRequest request, HttpServletResponse response) { SysFunction fun = new SysFunction(); try {
BeanUtils.populate(fun, request.getParameterMap());
Integer rtn = service.edit(fun);
if(rtn>0){
response.sendRedirect(Tools.Basepath(request, response)+"sys/fun?cmd=list");
}else{
request.setAttribute("msg", "保存系统功能失败!");
request.getRequestDispatcher("/sys/function/edit.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 初始化修改页面
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void toedit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SysFunction fun = new SysFunction();
fun.setFunid(Integer.parseInt(request.getParameter("id")));
fun = service.detail(fun);
if(fun!=null){
request.setAttribute("item",fun);
request.getRequestDispatcher("/sys/function/edit.jsp").forward(request, response);
}else{
request.setAttribute("msg", "需要修改的系统功能不存在。");
request.getRequestDispatcher("/error.jsp").forward(request, response);
}
} /**
* 查询功能列表
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void funlist(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { String sname = request.getParameter("sname");
SysFunction fun = new SysFunction();
if(sname!=null && !sname.equals("")){
fun.setFunname(sname);
} PageControl pc = new PageControl();
Integer currindex = 1;
if(request.getParameter("index")!=null){
currindex = Integer.parseInt(request.getParameter("index"));
}
pc.setCurrentindex(currindex);
//pc.setPagesize(5); Pager<SysFunction> pager = service.list(fun, pc);
request.setAttribute("pager", pager);
request.getRequestDispatcher("/sys/function/list.jsp").forward(request, response);
} /**
* 增加系统功能
* @param request
* @param response
*/
private void addfun(HttpServletRequest request, HttpServletResponse response) { SysFunction fun = new SysFunction();
try {
BeanUtils.populate(fun,request.getParameterMap());
Integer rtn = service.addfun(fun);
if(rtn>0){
response.sendRedirect(Tools.Basepath(request, response)+"sys/fun?cmd=list");
}else{
request.setAttribute("msg", "保存系统功能失败!");
request.getRequestDispatcher("/sys/function/add.jsp").forward(request, response);
} } catch (Exception e) { e.printStackTrace();
}
} }
package cn.itbaizhan.tyut.exam.sys.servlets;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import cn.itbaizhan.tyut.exam.common.PageControl;
import cn.itbaizhan.tyut.exam.common.Pager;
import cn.itbaizhan.tyut.exam.common.Tools;
import cn.itbaizhan.tyut.exam.model.Paper;
import cn.itbaizhan.tyut.exam.model.Subject;
import cn.itbaizhan.tyut.exam.sys.services.impl.PaperService;
import cn.itbaizhan.tyut.exam.sys.services.interfaces.IPaperService; public class PaperServlet extends HttpServlet {
IPaperService service = new PaperService(); protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String cmd = request.getParameter("cmd");
if(cmd.equals("add")){
addsubject(request,response);
}else if(cmd.equals("list")){
list(request,response);
}else if(cmd.equals("slist")){
slist(request,response);
}
} /**
* 生成试题功能
* @param request
* @param response
*/
private void addsubject(HttpServletRequest request, HttpServletResponse response) { Paper paper = new Paper();
try {
BeanUtils.populate(paper,request.getParameterMap());
Integer rtn = service.addpaper(paper) ;
if(rtn>0){
response.sendRedirect(Tools.Basepath(request, response)+"sys/paper?cmd=list");
}else{
request.setAttribute("msg", "增加试题功能失败!");
request.getRequestDispatcher("/sys/paper/add.jsp").forward(request, response);
} } catch (Exception e) {
e.printStackTrace();
}
}
/**
* 查询试题列表
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void list(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String pname = request.getParameter("pname");
Paper paper = new Paper();
if(pname!=null && !pname.equals("")){
paper.setPname(pname);
}
PageControl pc = new PageControl();
Integer currindex = 1;
if(request.getParameter("index")!=null){
currindex = Integer.parseInt(request.getParameter("index"));
}
pc.setCurrentindex(currindex);
//pc.setPagesize(5);
Pager<Paper> pager = service.list(paper, pc);
// System.out.println(pager.getList());;
request.setAttribute("pager", pager);
request.getRequestDispatcher("/sys/paper/list.jsp").forward(request, response);
}
private void slist(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Paper paper = new Paper();
String pname = new String(request.getParameter("pname").getBytes("iso-8859-1"), "utf-8");
paper.setPname(pname);
List<Subject> subjects = service.subjectlist(paper);
request.setAttribute("subjects", subjects);
request.getRequestDispatcher("/sys/paper/subjects.jsp").forward(request, response);
}
}
package cn.itbaizhan.tyut.exam.sys.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.List; import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import com.jspsmart.upload.SmartUpload; import cn.itbaizhan.tyut.exam.common.DBUnitHelper;
import cn.itbaizhan.tyut.exam.common.PageControl;
import cn.itbaizhan.tyut.exam.common.Pager;
import cn.itbaizhan.tyut.exam.common.Tools;
import cn.itbaizhan.tyut.exam.model.Paper;
import cn.itbaizhan.tyut.exam.model.Studentpaper;
import cn.itbaizhan.tyut.exam.model.Subject; import cn.itbaizhan.tyut.exam.sys.services.impl.StudentpaperService;
import cn.itbaizhan.tyut.exam.sys.services.impl.SubjectService;
import cn.itbaizhan.tyut.exam.sys.services.interfaces.IStudentpaperService;
import cn.itbaizhan.tyut.exam.sys.services.interfaces.ISubjectService; public class StudentpaperServlet extends HttpServlet { IStudentpaperService service = new StudentpaperService();
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String cmd = request.getParameter("cmd");
// if(cmd.equals("add")){
// add(request,response);
// }
// else if(cmd.equals("list")){
// list(request,response);
// }
// else if(cmd.equals("listByRightcount")){
// listByRightcount(request,response);
// }
if(cmd.equals("list")){
list(request,response);
}else if(cmd.equals("score")){
score(request,response);
}else if(cmd.equals("stupaper")){
StudentPaperList(request,response);
}
} /**
* 查询试卷得分
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void score(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Studentpaper stupaper = new Studentpaper();
try {
BeanUtils.populate(stupaper,request.getParameterMap());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(stupaper.getUserid()+stupaper.getSpid());
List<Studentpaper> studentpaper = service.listByRightcount(stupaper);
Integer score = studentpaper.get(0).getRightcount();
request.setAttribute("score", score);
PrintWriter out = response.getWriter(); out.println("您本次得分" + score * 2 + "分!");
out.flush();
out.close();
//request.getRequestDispatcher("/sys/paper/subjects.jsp").forward(request, response);
} /**
* 查询详细错题
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void list(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Studentpaper studentpaper = new Studentpaper();
PageControl pc = new PageControl();
Integer currindex = 1;
if(request.getParameter("index")!=null){
currindex = Integer.parseInt(request.getParameter("index"));
}
pc.setCurrentindex(currindex);
//pc.setPagesize(5);
studentpaper.setUserid((Integer) request.getSession().getAttribute("userid"));
studentpaper.setSpid(request.getParameter("spid"));
Pager<Subject> pager = service.list(studentpaper, pc);
request.setAttribute("pager", pager);
request.getRequestDispatcher("/user/paper/studenterror.jsp").forward(request, response);
} /**
* 增加试题功能
* @param request
* @param response
*//*
private void addsubject(HttpServletRequest request, HttpServletResponse response) { Subject subject = new Subject();
try {
BeanUtils.populate(subject,request.getParameterMap());
Integer rtn = service.addsubject(subject);
if(rtn>0){
response.sendRedirect(Tools.Basepath(request, response)+"sys/subject?cmd=list");
}else{
request.setAttribute("msg", "增加试题功能失败或请不要添加相同试题!");
request.getRequestDispatcher("/sys/subject/add.jsp").forward(request, response);
} } catch (Exception e) { e.printStackTrace();
}
}
*/
private void StudentPaperList(HttpServletRequest request, HttpServletResponse response) { Studentpaper studentpaper = new Studentpaper();
Integer userid = (Integer) request.getSession().getAttribute("userid");
studentpaper.setUserid(userid);
List<Studentpaper> papers = service.StudentPaperList(studentpaper);
request.setAttribute("papers", papers);
try {
request.getRequestDispatcher("/user/paper/studentpaper.jsp").forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package cn.itbaizhan.tyut.exam.sys.servlets;

import java.io.IOException;
import java.util.List; import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import org.apache.commons.beanutils.BeanUtils; import com.jspsmart.upload.SmartUpload; import cn.itbaizhan.tyut.exam.common.DBUnitHelper;
import cn.itbaizhan.tyut.exam.common.PageControl;
import cn.itbaizhan.tyut.exam.common.Pager;
import cn.itbaizhan.tyut.exam.common.Tools;
import cn.itbaizhan.tyut.exam.model.Subject; import cn.itbaizhan.tyut.exam.sys.services.impl.SubjectService;
import cn.itbaizhan.tyut.exam.sys.services.interfaces.ISubjectService; public class SubjectServlet extends HttpServlet { ISubjectService service = new SubjectService();
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String cmd = request.getParameter("cmd");
if(cmd.equals("add")){
addsubject(request,response);
}else if(cmd.equals("list")){
list(request,response);
}else if(cmd.equals("toedit")){
toedit(request,response);
}else if(cmd.equals("edit")){
edit(request,response);
}
} /**
* 修改试题功能
* @param request
* @param response
*/
private void edit(HttpServletRequest request, HttpServletResponse response) { Subject subject = new Subject(); try {
BeanUtils.populate(subject, request.getParameterMap());
Integer rtn = service.edit(subject);
if(rtn>0){
response.sendRedirect(Tools.Basepath(request, response)+"sys/subject?cmd=list");
}else{
request.setAttribute("msg", "编辑试题功能失败!");
request.getRequestDispatcher("/sys/subject/edit.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
} /**
* 初始化修改页面
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void toedit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Subject subject = new Subject();
subject.setSid(Integer.parseInt(request.getParameter("id")));
subject = service.detail(subject);
if(subject!=null){
request.setAttribute("item",subject);
request.getRequestDispatcher("/sys/subject/edit.jsp").forward(request, response);
}else{
request.setAttribute("msg", "需要修改的试题功能不存在。");
request.getRequestDispatcher("/error.jsp").forward(request, response);
}
} /**
* 查询试题列表
* @param request
* @param response
* @throws IOException
* @throws ServletException
*/
private void list(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException { String scontent = request.getParameter("scontent");
Subject subject = new Subject();
if(scontent!=null && !scontent.equals("")){
subject.setScontent(scontent);
} PageControl pc = new PageControl();
Integer currindex = 1;
if(request.getParameter("index")!=null){
currindex = Integer.parseInt(request.getParameter("index"));
}
pc.setCurrentindex(currindex);
//pc.setPagesize(5); Pager<Subject> pager = service.list(subject, pc);
request.setAttribute("pager", pager);
request.getRequestDispatcher("/sys/subject/list.jsp").forward(request, response);
} /**
* 增加试题功能
* @param request
* @param response
*/
private void addsubject(HttpServletRequest request, HttpServletResponse response) { Subject subject = new Subject();
try {
BeanUtils.populate(subject,request.getParameterMap());
Integer rtn = service.addsubject(subject);
if(rtn>0){
response.sendRedirect(Tools.Basepath(request, response)+"sys/subject?cmd=list");
}else{
request.setAttribute("msg", "增加试题功能失败或请不要添加相同试题!");
request.getRequestDispatcher("/sys/subject/add.jsp").forward(request, response);
} } catch (Exception e) { e.printStackTrace();
}
} }

写在最后

交流:3459067873

java jsp实现网络考试系统(mysql)的更多相关文章

  1. java网络考试系统的设计与实现 jsp 源码

    开发环境: Windows操作系统开发工具:MyEclipse/Eclipse + JDK+ Tomcat + MySQL 数据库 项目简介: 网络考试系统主要用于实现高校在线考试,基本功能包括:自动 ...

  2. 基于JSP的在线考试系统-JavaWeb项目-有源码

    开发工具:Myeclipse/Eclipse + MySQL + Tomcat 系统简介: 网络考试系统主要用于实现高校在线考试,基本功能包括:自动组卷.试卷发布.试卷批阅.试卷成绩统计等.本系统结构 ...

  3. IT增值服务-客户案例(三):合肥薪火科技,Java和P2P网络借贷系统开发指导

    客户整体情况: 合肥薪火科技,是安徽合肥一家主营微信开发和运营的中小企业,http://weimarket.cn/. 这家公司筹备.创立.曲折创业的经历,我一直有关注.因为2个老板,都是我的同学校友, ...

  4. ssm+mysql+jsp打造在线考试系统WeKnow-学生端

    一.登陆模块 前台提交账号和密码传到后台处理控制层 1.1 首先是控制器 @RequestMapping(value="/studentLogin", method=Request ...

  5. 课程设计之"网络考试系统"(php、Extjs)

    1.TestSystem大概结构框图 2.数据库设计(11张表) 数据库名称:db_testsystem 数据库表: tb_admin 记录题库管理员帐户信息 代码 tb_allcontent 记录随 ...

  6. 基于Web在线考试系统的设计与实现

    这是一个课程设计的文档,源码及文档数据库我都修改过了,貌似这里复制过来的时候图片不能贴出,下载地址:http://download.csdn.net/detail/sdksdk0/9361973   ...

  7. Java学习之网络编程实例

    转自:http://www.cnblogs.com/springcsc/archive/2009/12/03/1616413.html 多谢分享 网络编程 网络编程对于很多的初学者来说,都是很向往的一 ...

  8. Java进阶之网络编程

    网络编程 网络编程对于很多的初学者来说,都是很向往的一种编程技能,但是很多的初学者却因为很长一段时间无法进入网络编程的大门而放弃了对于该部分技术的学习. 在 学习网络编程以前,很多初学者可能觉得网络编 ...

  9. java web项目优化记录:优化考试系统

    考试系统在进行压力測试时发现,并发量高之后出现了button无反应.试题答案不能写到数据库的问题,于是针对这些核心问题,进行了优化. 数据库方面: Select语句:Select * from TEB ...

随机推荐

  1. 【Redis学习专题】- Redis主从+哨兵集群部署

    集群版本: redis-4.0.14 集群节点: 节点角色 IP redis-master 10.100.8.21 redis-slave1 10.100.8.22 redis-slave2 10.1 ...

  2. Python实现初始化不同的变量类型为空值

    常见的数字,字符,很简单,不多解释. 列表List的其值是[x,y,z]的形式 字典Dictionary的值是{x:a, y:b, z:c}的形式 元组Tuple的值是(a,b,c)的形式 所以,这些 ...

  3. Oracle连接报错之IO异常(The Network Adapter could not establish the connection)

    简单介绍:自己封装oracle jdbc的一些常用功能jar包,自己本机玩没啥问题,给别人玩儿,发现总是抛异常 IO异常(The Network Adapter could not establish ...

  4. css中的名词

    用到的单词 current 当前 hover 悬停 selected 挑选 disabled 禁用 focus 得到焦点 blur 失去焦点 checked 勾选 success 成功 error 出 ...

  5. python socket函数详解

    关于socket函数,每个的意义和基本功能都知道,但每次使用都会去百度,参数到底是什么,返回值代表什么意义,就是说用的少,也记得不够精确.每次都查半天,经常烦恼于此.索性都弄得清楚.通透,并记录下来, ...

  6. Blash数组 c++

    //输入一个数作为Blash数组的根, //对于该数组的每一个数x,x*2+1 x*3+1均在该数组 //并且该数组没有其他数字 //该数组升序排列 //输入a,n 输出该数组第n个数 // // # ...

  7. PHP系列之钩子

    PHP 提供的钩子 PHP 和 Zend Engine 为扩展提供了许多不同的钩子,这些扩展允许扩展开发人员以 PHP userland 无法提供的方式控制 PHP 运行时. 本章将展示各种钩子和从扩 ...

  8. python小题目汇总

    1.编程计算两个日期之间的天数与周数 Python时间处理---dateutil模块: dateutil模块主要有两个函数,parser和rrule. 其中parser是根据字符串解析成datetim ...

  9. Python File write() 方法

    概述 write() 方法用于向文件中写入指定字符串.高佣联盟 www.cgewang.com 在文件关闭前或缓冲区刷新前,字符串内容存储在缓冲区中,这时你在文件中是看不到写入的内容的. 如果文件打开 ...

  10. 畅购商城(二):分布式文件系统FastDFS

    好好学习,天天向上 本文已收录至我的Github仓库DayDayUP:github.com/RobodLee/DayDayUP,欢迎Star,更多文章请前往:目录导航 畅购商城(一):环境搭建 畅购商 ...