智能移動(dòng)方向Jsp開發(fā)實(shí)訓(xùn)任務(wù)書及實(shí)訓(xùn)報(bào)告在線考試系統(tǒng)的制作
學(xué)校代碼: 10128 學(xué) 號(hào): 201320905047 JSP開發(fā)實(shí)訓(xùn)報(bào)告書題 目:在線考試系統(tǒng)的制作學(xué)生姓名:張志勇學(xué) 院:理學(xué)院班 級(jí):信計(jì)13-1指導(dǎo)教師:李曉瑜、宋健、賴俊峰 二一六年一月一、項(xiàng)目名稱在線考試系統(tǒng)-題庫(kù)子系統(tǒng)二、功能要求 a、用戶管理 b、課程管理 c、題庫(kù)管理 三、需求分析 在線考試系統(tǒng)-題庫(kù)子系統(tǒng)的用戶包括用戶管理員,試題管理員和題庫(kù)使用人員,旨在建立一個(gè)獨(dú)立的題庫(kù)系統(tǒng),為在線考試生成試卷提供支持,包含用戶管理,科目管理,試題管理,生成試卷,試卷分析等內(nèi)容,為用戶提供了一個(gè)快速、全面、準(zhǔn)確的試題管理平臺(tái)。四、設(shè)計(jì)思想 a、使用Java Web技術(shù)實(shí)現(xiàn) b、使用Mysql存儲(chǔ)數(shù)據(jù) c、基于MVC方式實(shí)現(xiàn)用例設(shè)計(jì)思路:(如下圖)分步詳解:第一步:創(chuàng)建項(xiàng)目名(zhangzhiyong);第二步:創(chuàng)建項(xiàng)目所需要的包;第三步:導(dǎo)入需要的工具;第四步:創(chuàng)建數(shù)據(jù)庫(kù)的連接;第五步:需要的準(zhǔn)備工作做好之后,明確先做用戶管理系統(tǒng)(登錄,查看,刪除,修改,增加,退出;);第六步:做好用戶管理之后進(jìn)行科目管理(增加,刪除,修改,查看;);第七步:接下來進(jìn)行知識(shí)點(diǎn)管理(增加,刪除,修改,查看;);五、具體實(shí)現(xiàn)一用戶管理:需要的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("<script type=text/javascript>");out.print("alert(用戶名或密碼錯(cuò)誤,請(qǐng)重新輸入!);");out.print("window.location=login.jsp;");out.print("</script>");else if("logout".equals(type)request.getSession().invalidate();out.print("<script type=text/javascript>");out.print("window.location=login.jsp;");out.print("</script>");else if("list".equals(type)List<User> 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();/連接對(duì)象PreparedStatement pstmt=null;/語句對(duì)象/下邊是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=更新的行數(shù)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<User> selectAll()List<User> list=new ArrayList<User>();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();/連接對(duì)象PreparedStatement pstmt=null;/語句對(duì)象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=更新的行數(shù)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();/連接對(duì)象PreparedStatement pstmt=null;/語句對(duì)象String sql="delete from userss where id=?"trypstmt=conn.prepareStatement(sql);pstmt.setInt(1,id);m=pstmt.executeUpdate();/n=更新的行數(shù)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