——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7、Tomcat≥8
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet考试系统(java+jsp+bootstrap+servlet+mysql)
项目介绍
本系统分为两个角色,一个是考生,一个是管理员, 考生功能如下: 登录、选择考试科目、选择考卷、在线考试、提交试卷、并且查询自己的考试成绩
管理员功能如下: 登录、添加试卷、并且添加试卷里的题目、编辑科目、还可以查询所有考生的成绩
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
技术栈
后端:servlet 2. 前端:JSP+bootstrap+jQuery
使用说明
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/ 登录
——————————CodeStart——————————
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 if (page > 0 ) { tempPage = (page - 1 ) * row; } List<Map<String, String>> ksfs = BusinessService.getKsfs( username, tempPage, row); Long count = BusinessService.getInfoCount(username); Integer lastPage = 0 ; if (count % row > 0 ) { lastPage = Integer.parseInt((count / row + 1 ) + "" ); } else { lastPage = Integer.parseInt((count / row) + "" ); } String HtmlPage = Util.page(page, lastPage); req.setAttribute("HtmlPage" , HtmlPage); req.setAttribute("ksfs" , ksfs); req.getRequestDispatcher("WEB-INF/view/chaxun.jsp" ).forward( req, resp); } else if ("gocx" .equals(action)) { req.getRequestDispatcher("/actionKfcx.jsp" ).forward(req, resp); }else if ("aaa" .equals(action)){ String pageStr = req.getParameter("page" ); String rowStr = req.getParameter("rows" ); if (pageStr == null ) { pageStr = "1" ; } if (rowStr == null ) { rowStr = "100" ; } Integer page = Integer.parseInt(pageStr); Integer row = Integer.parseInt(rowStr); Integer tempPage = 0 ;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 Integer page = Integer.parseInt(pageStr); Integer row = Integer.parseInt(rowStr); Long count = BusinessService.getMainCount(); if (page > 0 ){ page = (page-1 )*row; } List<Map<String, String>> model = BusinessService.getMain(page, row); String result = null ; try { result = MrksUtils.getEasyUIDataGridModel(model, count); } catch (Exception e) { e.printStackTrace(); } MrksUtils.responseWriteJson(resp, result); }else { req.getRequestDispatcher("WEB-INF/view/main.jsp" ).forward(req, resp); } } @Override protected void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter("action" ); if ("add" .equals(action)){ String ID = UUID.randomUUID().toString(); String 标题 = req.getParameter(BusinessMain.标题.toString()); String 外键 = req.getParameter(BusinessMain.外键.toString()); String 答题时间 = req.getParameter(BusinessMain.答题时间.toString()); int result = BusinessService.insertMain(ID,标题,外键,答题时间); if (result == 1 ){ MrksUtils.responseWriteJson(resp, "{\"success\":\"YES\"}" ); }else { MrksUtils.responseWriteJson(resp, "{\"success\":\"NO\"}" ); } }else if ("edit" .equals(action)){ String ID = req.getParameter(BusinessMain.ID.toString()); String 标题 = req.getParameter(BusinessMain.标题.toString());
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ @Override public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this .doPost(request, response); } @Override public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html" ); res.setCharacterEncoding("utf-8" ); PrintWriter out = res.getWriter(); String 用户名 = req.getParameter("USERNAME" ); System.out.println(用户名); String 密码 = req.getParameter(UserInfo.密码.toString()); System.out.println(密码); Map<String, Object> userInfoMap = 系统服务.selectUserInfoBy用户名(用户名); if (userInfoMap != null ){ String 取出的密码 = (String)userInfoMap.get(UserInfo.密码.toString());
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 * 连接关闭调用的方法 */ @OnClose public void onClose () { try { context.removeAttribute((String)httpSession.getAttribute(UserInfo.用户名.toString())); } catch (Exception e) { e.printStackTrace(); } } @OnMessage public void onMessage (String message, Session session) { if (message != null ){ switch (message) { case "start" : String time = (String)httpSession.getAttribute(BusinessMain.答题时间.toString()); Long targetMinute = 1000L *60L *Long.parseLong(time); Date current = new Date(); Long target = current.getTime()+targetMinute; Timekeeping timekeeping = new Timekeeping(target,session); Thread thread = new Thread(timekeeping);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 @ServerEndpoint(value = "/mysocketTest",configurator=BaseContext.class) public class MySocket2 { private static final long serialVersionUID = 79990006013872453L ; private static int onlineCount = 0 ; private static CopyOnWriteArraySet<MySocket2> webSocketSet = new CopyOnWriteArraySet<MySocket2>(); public static java.util.concurrent.ConcurrentHashMap<String , String> useronline = new java.util.concurrent.ConcurrentHashMap<String , String>(); private Session session; private ServletContext context = null ; private HttpSession httpSession = null ; @OnOpen public void onOpen (Session session,EndpointConfig config) throws IOException { this .session = session; webSocketSet.add(this ); context = (ServletContext)config.getUserProperties().get(ServletContext.class.getName()); httpSession = (HttpSession)config.getUserProperties().get(HttpSession.class.getName()); Map<String,Object> userInfoMap = (Map<String,Object>)httpSession.getAttribute("userInof" );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 try { result = MrksUtils.getEasyUIDataGridModel(ksfs, count); } catch (Exception e) { e.printStackTrace(); } MrksUtils.responseWriteJson(resp, result); } } else { resp.sendRedirect("login.jsp" ); } } @Override protected void doPost (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Map<String, String[]> parmMap = req.getParameterMap(); HttpSession session = req.getSession(); String username = (String) session .getAttribute(UserInfo.用户名.toString()); if (BusinessService.countScore(parmMap, username) == 1 ) { resp.sendRedirect("action?act=kfcx" ); } else { req.getRequestDispatcher("/login.jsp" ).forward(req, resp); } }
——————————PayStart——————————
项目链接: https://javayms.github.io?id=051122542008200rv https://javayms.pages.dev?id=051122542008200rv