智能移动方向Jsp开发实训任务书及实训报告在线考试系统的制作

上传人:仙*** 文档编号:35090840 上传时间:2021-10-25 格式:DOC 页数:44 大小:841.50KB
返回 下载 相关 举报
智能移动方向Jsp开发实训任务书及实训报告在线考试系统的制作_第1页
第1页 / 共44页
智能移动方向Jsp开发实训任务书及实训报告在线考试系统的制作_第2页
第2页 / 共44页
智能移动方向Jsp开发实训任务书及实训报告在线考试系统的制作_第3页
第3页 / 共44页
点击查看更多>>
资源描述
学校代码: 10128 学 号: 201320905047 JSP开发实训报告书题 目:在线考试系统的制作学生姓名:张志勇学 院:理学院班 级:信计13-1指导教师:李晓瑜、宋健、赖俊峰 二一六年一月一、项目名称在线考试系统-题库子系统二、功能要求 a、用户管理 b、课程管理 c、题库管理 三、需求分析 在线考试系统-题库子系统的用户包括用户管理员,试题管理员和题库使用人员,旨在建立一个独立的题库系统,为在线考试生成试卷提供支持,包含用户管理,科目管理,试题管理,生成试卷,试卷分析等内容,为用户提供了一个快速、全面、准确的试题管理平台。四、设计思想 a、使用Java Web技术实现 b、使用Mysql存储数据 c、基于MVC方式实现用例设计思路:(如下图)分步详解:第一步:创建项目名(zhangzhiyong);第二步:创建项目所需要的包;第三步:导入需要的工具;第四步:创建数据库的连接;第五步:需要的准备工作做好之后,明确先做用户管理系统(登录,查看,删除,修改,增加,退出;);第六步:做好用户管理之后进行科目管理(增加,删除,修改,查看;);第七步:接下来进行知识点管理(增加,删除,修改,查看;);五、具体实现一用户管理:需要的servlet:(user servlet)package cn.zhangzhiyong.service;import java.io.IOException;import java.io.PrintWriter;import java.util.List;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.dao.UserDAO;import cn.zhangzhiyong.util.RequestUtil;WebServlet(/UserServlet)public class UserServlet extends HttpServlet private static final long serialVersionUID = 1L; public UserServlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);response.setContentType(text/html;charset=utf-8);PrintWriter out=response.getWriter();String type=request.getParameter(type);String userLogname=request.getParameter(userLogname);String userPwd=request.getParameter(userPwd);UserDAO dao=new UserDAO();User user=dao.login(userLogname, userPwd);if(login.equals(type)if(user!=null)request.getSession().setAttribute(SESSION_USER,user);response.sendRedirect(res/index.html);elseout.print();out.print(alert(用户名或密码错误,请重新输入!););out.print(window.location=login.jsp;);out.print();else if(logout.equals(type)request.getSession().invalidate();out.print();out.print(window.location=login.jsp;);out.print();else if(list.equals(type)List list=dao.selectAll();request.setAttribute(list,list);request.getRequestDispatcher(res/user.jsp).forward(request, response);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);(user add servlet)package cn.zhangzhiyong.service;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.dao.UserDAO;import cn.zhangzhiyong.util.RequestUtil;WebServlet(/UserAddServlet)public class UserAddServlet extends HttpServlet private static final long serialVersionUID = 1L; public UserAddServlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);String login=request.getParameter(login);String name=request.getParameter(name);int type=(request.getParameter(type)=null)?3:Integer.parseInt(request.getParameter(type);int status=(request.getParameter(status)=null)?1:Integer.parseInt(request.getParameter(status);User user=new User(login,name,type,status);UserDAO dao=new UserDAO();int n=dao.save(user);if(n=1)response.sendRedirect(UserServlet?type=list);elseresponse.sendRedirect(index.jsp);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);(UserDeleteServlet)package cn.zhangzhiyong.service;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.dao.UserDAO;import cn.zhangzhiyong.util.RequestUtil;import cn.zhangzhiyong.util.WebUtil;WebServlet(/UserDeleteServlet)public class UserDeleteServlet extends HttpServlet private static final long serialVersionUID = 1L; public UserDeleteServlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(UTF-8);/ System.out.println(request.getParameter(Id); int id=RequestUtil.getInt(request,Id); UserDAO dao=new UserDAO(); dao.delete(id); WebUtil.forward(request, response, UserServlet?type=list); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException / TODO Auto-generated method stubdoGet(request, response);(UserUpdate1Servlet)package cn.zhangzhiyong.service;import java.io.File;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.Part;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.dao.UserDAO;import cn.zhangzhiyong.util.RequestUtil;import cn.zhangzhiyong.util.WebUtil;WebServlet(/UserUpdate1Servlet)public class UserUpdate1Servlet extends HttpServlet private static final long serialVersionUID = 1L; public UserUpdate1Servlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);response.setContentType(text/html;charset=utf-8);int id=RequestUtil.getInt(request,Id); request.setAttribute(id, id); request.getRequestDispatcher(res/user-update.jsp).forward(request, response); protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException / TODO Auto-generated method stubdoGet(request, response);(UserUpdateServlet)package cn.zhangzhiyong.service;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.dao.UserDAO;import cn.zhangzhiyong.util.RequestUtil;WebServlet(/UserUpdateServlet)public class UserUpdateServlet extends HttpServlet private static final long serialVersionUID = 1L; public UserUpdateServlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);String login=request.getParameter(login);String name=request.getParameter(name);String passwd=request.getParameter(passwd);int type=Integer.parseInt(request.getParameter(type);int status=Integer.parseInt(request.getParameter(status);int id=RequestUtil.getInt(request,id);User users=new User(login,name,type,status);UserDAO dao=new UserDAO();int n=dao.update(users);if(n=1)response.sendRedirect(UserServlet?type=list);elseresponse.sendRedirect(index.jsp);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);(UserViewServlet)package cn.zhangzhiyong.service;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.dao.UserDAO;import cn.zhangzhiyong.util.RequestUtil;WebServlet(/UserViewServlet)public class UserViewServlet extends HttpServlet private static final long serialVersionUID = 1L; public UserViewServlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);response.setContentType(text/html;charset=utf-8);PrintWriter out=response.getWriter();String type=request.getParameter(type);String userLogname=request.getParameter(userLogname);String userPwd=request.getParameter(userPwd);UserDAO dao=new UserDAO();int id=RequestUtil.getInt(request,Id);User user1=dao.selectById(id);request.setAttribute(user,user1);request.getRequestDispatcher(res/user-show.jsp).forward(request, response);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);需要的类:package cn.zhangzhiyong.bean;import java.sql.Timestamp;public class User public static final String passwd=123456;private int id;private String login;private String name;private String password;private int type;private int status;private Timestamp last_login; public User(String login2, String name2, int type2, int status2) super();this.login=login2;this.name=name2;this.type=type2;this.status=status2;public User() public User(int id2) this.id=id2;public int getId() return id;public void setId(int id) this.id = id;public String getLogin() return login;public void setLogin(String login) this.login = login;public String getName() return name;public void setName(String name) this.name = name;public String getPassword() return password;public void setPassword(String password) this.password = password;public int getType() return type;public void setType(int type) this.type = type;public int getStatus() return status;public void setStatus(int status) this.status = status;public Timestamp getLast_login() return last_login;public void setLast_login(Timestamp last_login) this.last_login = last_login;需要的dao:package cn.zhangzhiyong.dao;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import cn.zhangzhiyong.bean.User;import cn.zhangzhiyong.util.DBUtil;public class UserDAO /userdao中的save方法public int save(User user)int n=-1;Connection conn=DBUtil.getConnection();/连接对象PreparedStatement pstmt=null;/语句对象/下边是s语句String sql=insert into userss+ values(DL_USERSS.NEXTVAL,?,?,123456,?,?,sysdate);trypstmt=conn.prepareStatement(sql);pstmt.setString(1, user.getLogin();pstmt.setString(2, user.getName();pstmt.setInt(3, user.getType();pstmt.setInt(4, user.getStatus();n=pstmt.executeUpdate();/n=更新的行数catch(SQLException e)e.printStackTrace();finallyDBUtil.closeJDBC(null, pstmt, conn);return n;public User login(String userLogname, String userPwd) Connection conn=DBUtil.getConnection();PreparedStatement pstmt=null;ResultSet rs=null;User u=null;String sql=select id,login,name,passwd,type,status,last_login+ from users where login=? and passwd=?;trypstmt=conn.prepareStatement(sql);pstmt.setString(1, userLogname);pstmt.setString(2, userPwd);rs=pstmt.executeQuery();if(rs.next()u=new User();u.setId(rs.getInt(1);u.setLogin(rs.getString(2);u.setName(rs.getString(3);u.setPassword(rs.getString(4);u.setType(rs.getInt(5);u.setStatus(rs.getInt(6);u.setLast_login(rs.getTimestamp(7);catch(SQLException e)e.printStackTrace();finallyDBUtil.closeJDBC(rs, pstmt, conn);return u;public User selectById(int Id) User user=new User();Connection conn=DBUtil.getConnection();PreparedStatement pstmt=null;ResultSet rs=null;String sql=select * from userss where id=?;trypstmt=conn.prepareStatement(sql);pstmt.setInt(1, Id);rs=pstmt.executeQuery();if(rs.next()user.setId(rs.getInt(1);user.setLogin(rs.getString(2);user.setName(rs.getString(3);user.setPassword(rs.getString(4);user.setType(rs.getInt(5);user.setStatus(rs.getInt(6);catch(SQLException e)e.printStackTrace();finallyDBUtil.closeJDBC(rs, pstmt, conn);return user;public List selectAll()List list=new ArrayList();Connection conn=DBUtil.getConnection();PreparedStatement pstmt=null;ResultSet rs=null;String sql=select * from userss order by id desc;trypstmt=conn.prepareStatement(sql);rs=pstmt.executeQuery();while(rs.next()User user=new User();user.setId(rs.getInt(1);user.setLogin(rs.getString(2);user.setName(rs.getString(3);user.setPassword(rs.getString(4);user.setType(rs.getInt(5);user.setStatus(rs.getInt(6);list.add(user);catch(SQLException e)e.printStackTrace();finallyDBUtil.closeJDBC(rs, pstmt, conn);return list;/userdao中的update方法public int update(User users)int n=-1;Connection conn=DBUtil.getConnection();/连接对象PreparedStatement pstmt=null;/语句对象String sql=update userss + set login=?,name=?,passwd=123,type=?,status=? where id=?;trypstmt=conn.prepareStatement(sql);pstmt.setString(1, users.getLogin();pstmt.setString(2, users.getName();pstmt.setInt(3, users.getType();pstmt.setInt(4, users.getStatus();pstmt.setInt(5,users.getId();n=pstmt.executeUpdate();/n=更新的行数catch(SQLException e)e.printStackTrace();finallyDBUtil.closeJDBC(null, pstmt, conn);return n;/userdao中的delete 方法public int delete(int id)int m=-1;Connection conn=DBUtil.getConnection();/连接对象PreparedStatement pstmt=null;/语句对象String sql=delete from userss where id=?;trypstmt=conn.prepareStatement(sql);pstmt.setInt(1,id);m=pstmt.executeUpdate();/n=更新的行数catch(SQLException e)e.printStackTrace();finallyDBUtil.closeJDBC(null, pstmt, conn);return m;二科目管理:需要的servlet:(SubjectViewServlet)package cn.zhangzhiyong.service;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.Subject;import cn.zhangzhiyong.dao.SubjectDAO;import cn.zhangzhiyong.util.RequestUtil;/* * Servlet implementation class SubjectViewServlet */WebServlet(/SubjectViewServlet)public class SubjectViewServlet extends HttpServlet private static final long serialVersionUID = 1L; public SubjectViewServlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);response.setContentType(text/html;charset=utf-8);SubjectDAO dao=new SubjectDAO();int id=RequestUtil.getInt(request,id);Subject subject=dao.selectById(id);request.setAttribute(Subject,subject);request.getRequestDispatcher(res/subject-show.jsp).forward(request, response);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);(SubjectUpdate2Servlet)package cn.zhangzhiyong.service;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.Subject;import cn.zhangzhiyong.dao.SubjectDAO;import cn.zhangzhiyong.util.RequestUtil;WebServlet(/SubjectUpdate2Servlet)public class SubjectUpdate2Servlet extends HttpServlet private static final long serialVersionUID = 1L; public SubjectUpdate2Servlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException Subject subject =new Subject();subject.setKname(RequestUtil.getString(request, kname);subject.setType(RequestUtil.getInt(request, type);subject.setKint(RequestUtil.getString(request, kint);subject.setId(RequestUtil.getInt(request, id);SubjectDAO dao=new SubjectDAO();int n=dao.update(subject);response.sendRedirect(ServletListServlet?type=list);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);(SubjectUpdate0Servlet)package cn.zhangzhiyong.service;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.bean.Subject;import cn.zhangzhiyong.dao.SubjectDAO;import cn.zhangzhiyong.util.RequestUtil;/* * Servlet implementation class SubjectUpdate0Servlet */WebServlet(/SubjectUpdate0Servlet)public class SubjectUpdate0Servlet extends HttpServlet private static final long serialVersionUID = 1L; public SubjectUpdate0Servlet() super(); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException request.setCharacterEncoding(utf-8);response.setContentType(text/html;charset=utf-8);SubjectDAO dao=new SubjectDAO();int id=RequestUtil.getInt(request,id);Subject subject=dao.selectById(id);request.setAttribute(Subject,subject);request.getRequestDispatcher(res/subject-update.jsp).forward(request, response);protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException doGet(request, response);(SubjectListServlet)package cn.zhangzhiyong.service;import java.io.IOException;import java.util.List;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import cn.zhangzhiyong.dao.SubjectDAO;import cn.zhangzhiyong.bea
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 压缩资料 > 基础医学


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!