基于javaweb+mysql的jsp+servlet学生宿舍管理系统(学生、管理员)(java+servlet+mysql+jsp)
基于javaweb+mysql的jsp+servlet学生宿舍管理系统(学生、管理员)(java+servlet+mysql+jsp)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet学生宿舍管理系统(学生、管理员)(java+servlet+mysql+jsp)
管理员
admin 123456
学生
student 123456
注:【学生入住管理-学生入住登记】的姓名需要与【系统管理-添加用户】的姓名一致,学生登录后才能关联到他的详细信息
JAVA-Web实现的学生宿舍管理系统
学生宿舍管理系统旨在开发出一个方便管理员与学生使用的信息系统。
通过本系统可以实现
管理员对学生信息的增删查改、对卫生信息的登记与查看、对综合宿舍信息的增删查改、对宿舍维修状况的整体把握与处理;
同时学生也可使用本系统进行查看与修改个人信息、维修报修、查看卫生评比等操作。
本项目使用 Java 做为Servlet端语言,MySQL作为数据库,使用JSP技术实现动态网页的制作,以Tomcat 9.0作为服务器,页面之间通过重定向技术实现通信。HTTP协议是无连接的,我们使用Session来保持用户的登陆状态,在页面跳转时不丢失信息;对每一个页面分别建立一个Servlet进行表单处理;对所有数据库的实例对象建立一个Dao.Factory类,所有页面通过调用Dao.Factory来创建数据库的后台实例,通过实现Dao接口来进行数据库链接。
数据库使用Mysql,连接端口等可根据自己情况更改。
/** * Servlet implementation class UpdateHelServlet */ @WebServlet("/UpdateHelServlet") public class UpdateHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UpdateHelServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); HttpSession session=request.getSession(); int did=Integer.parseInt(session.getAttribute("id").toString()); String section=request.getParameter("dorSection1")+request.getParameter("dorSection2"); int number=Integer.parseInt(request.getParameter("upNumber")); String person=request.getParameter("upPerson"); String result=request.getParameter("upResult"); String date=request.getParameter("upDate"); String remark=request.getParameter("upRemark"); if(DaoFactory.getHealthInstance().update(did, section, number, person, result, date, remark)>0) { ResultSet rs=DaoFactory.getHealthInstance().queryAll(); int[] sumInfo=DaoFactory.getHealthInstance().sumInfo(); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("he_id"); sb.append(""); }catch(SQLException e) { e.printStackTrace(); } HttpSession session=request.getSession(); session.setAttribute("query", sb); response.sendRedirect("Student/healthInfo.jsp"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } } /** * Servlet implementation class SQueryallHelServlet */ @WebServlet("/SQueryallHelServlet") public class SQueryallHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" ");/** * Servlet implementation class DeleteHelServlet */ @WebServlet("/DeleteHelServlet") public class DeleteHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public DeleteHelServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); int getid=Integer.valueOf(request.getParameter("id")); if(DaoFactory.getHealthInstance().delete(getid)>0) { ResultSet rs=DaoFactory.getHealthInstance().queryAll(); int[] sumInfo=DaoFactory.getHealthInstance().sumInfo(); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("he_id"); sb.append(""); "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" "); sb.append(rs.getString("he_person")); sb.append(" "); sb.append(rs.getString("he_result")); sb.append(" "); sb.append(rs.getString("he_date")); sb.append(" "); sb.append(rs.getString("he_remark")); sb.append("sb.append(" "); sb.append("不合格:"+String.valueOf(sumInfo1[3])+"个"); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append("
} rs.close(); }catch(SQLException e) { e.printStackTrace(); } HttpSession session=request.getSession(); session.setAttribute("query", sb); response.sendRedirect("Admin/studentInfo.jsp"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } } /** * Servlet implementation class QueryReServlet */ @WebServlet("/QueryReServlet") public class QueryReServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public QueryReServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } } /** * Servlet implementation class QueryHelServlet */ @WebServlet("/QueryHelServlet") public class QueryHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public QueryHelServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String section1=request.getParameter("dorSection1");
*/ public QueryStuServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String id=request.getParameter("stuId"); String name=request.getParameter("stuName"); String school=request.getParameter("stuSchool"); String major=request.getParameter("stuMajor"); String gender=request.getParameter("stuGender"); String education=request.getParameter("stuEducation"); String section1=request.getParameter("dorSection1"); String section2=request.getParameter("dorSection2"); String number=request.getParameter("dorNumber"); ResultSet rs=DaoFactory.getStudentInstance().query(id, name, gender, school, major, education, section1, section2, number); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { sb.append(" "); sb.append(rs.getString("st_id")); sb.append(" "); sb.append(rs.getString("st_name")); sb.append(" "); sb.append(rs.getString("st_gender")); sb.append(" "); sb.append(rs.getString("st_nativeplace")); sb.append(" "); sb.append(rs.getString("st_birthday")); sb.append(" "); sb.append(rs.getString("st_school")); sb.append(" "); sb.append(rs.getString("st_major")); sb.append(" "); sb.append(rs.getString("st_enrolltime")); sb.append(" "); sb.append(rs.getString("st_length"));* Servlet implementation class QueryHelServlet */ @WebServlet("/QueryHelServlet") public class QueryHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public QueryHelServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String section1=request.getParameter("dorSection1"); String section2=request.getParameter("dorSection2"); String number=request.getParameter("dorNumber"); String person=request.getParameter("helPerson"); String result=request.getParameter("helResult"); ResultSet rs=DaoFactory.getHealthInstance().query(section1, section2, number, person, result); int[] sumInfo1=DaoFactory.getHealthInstance().sumInfo1(section1, section2, number, person, result); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("he_id"); sb.append(" "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" "); sb.append(rs.getString("he_person")); sb.append(" "); sb.append(rs.getString("he_result")); sb.append(" ");String remark=request.getParameter("upRemark"); if(DaoFactory.getHealthInstance().update(did, section, number, person, result, date, remark)>0) { ResultSet rs=DaoFactory.getHealthInstance().queryAll(); int[] sumInfo=DaoFactory.getHealthInstance().sumInfo(); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("he_id"); sb.append(""); } rs.close(); sb.append(" "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" "); sb.append(rs.getString("he_person")); sb.append(" "); sb.append(rs.getString("he_result")); sb.append(" "); sb.append(rs.getString("he_date")); sb.append(" "); sb.append(rs.getString("he_remark")); sb.append(""); }catch(SQLException e) { e.printStackTrace(); } HttpSession session=request.getSession(); session.setAttribute("query", sb); response.sendRedirect("Admin/dormitoryInfo.jsp"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } } /** * Servlet implementation class QueryHelServlet */ @WebServlet("/QueryHelServlet") public class QueryHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public QueryHelServlet() { super(); // TODO Auto-generated constructor stub } "); sb.append("合计"); sb.append(" "); sb.append("优秀:"+String.valueOf(sumInfo[0])+"个"); sb.append(" "); sb.append("良好:"+String.valueOf(sumInfo[1])+"个"); sb.append(" "); sb.append("合格:"+String.valueOf(sumInfo[2])+"个"); sb.append(" "); sb.append("不合格:"+String.valueOf(sumInfo[3])+"个"); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append(" ");/** * Servlet implementation class SQueryHelServlet */ @WebServlet("/SQueryHelServlet") public class SQueryHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public SQueryHelServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String section1=request.getParameter("dorSection1"); String section2=request.getParameter("dorSection2"); String number=request.getParameter("dorNumber"); String person=request.getParameter("helPerson"); String result=request.getParameter("helResult"); ResultSet rs=DaoFactory.getHealthInstance().query(section1, section2, number, person, result); int[] sumInfo1=DaoFactory.getHealthInstance().sumInfo1(section1, section2, number, person, result); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("he_id"); sb.append(""); }catch(SQLException e) { e.printStackTrace(); } HttpSession session=request.getSession(); session.setAttribute("query", sb); response.sendRedirect("Admin/healthInfo.jsp"); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } } "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number"));ResultSet rs=DaoFactory.getStudentInstance().query(id, name, gender, school, major, education, section1, section2, number); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { sb.append(""); } rs.close(); }catch(SQLException e) { e.printStackTrace(); } HttpSession session=request.getSession(); session.setAttribute("query", sb); response.sendRedirect("Admin/studentInfo.jsp"); } /** "); sb.append(rs.getString("st_id")); sb.append(" "); sb.append(rs.getString("st_name")); sb.append(" "); sb.append(rs.getString("st_gender")); sb.append(" "); sb.append(rs.getString("st_nativeplace")); sb.append(" "); sb.append(rs.getString("st_birthday")); sb.append(" "); sb.append(rs.getString("st_school")); sb.append(" "); sb.append(rs.getString("st_major")); sb.append(" "); sb.append(rs.getString("st_enrolltime")); sb.append(" "); sb.append(rs.getString("st_length")); sb.append(" "); sb.append(rs.getString("st_education")); sb.append(" "); sb.append(rs.getString("st_phone")); sb.append(" "); sb.append(rs.getString("st_remark")); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append("sb.append(" "); sb.append("合格:"+String.valueOf(sumInfo[2])+"个"); sb.append(" "); sb.append("不合格:"+String.valueOf(sumInfo[3])+"个"); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append("sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append("/** * @see HttpServlet#HttpServlet() */ public QueryallLrServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); ResultSet rs=DaoFactory.getRepairsmanInstance().queryAll1(); StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("re_id"); sb.append(""); } rs.close(); "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" "); sb.append(rs.getString("re_item")); sb.append(" "); sb.append(rs.getString("re_date")); sb.append(" "); sb.append(rs.getString("re_reason")); sb.append(" "); sb.append(rs.getString("re_name")); sb.append(" "); sb.append(rs.getString("re_phone")); sb.append(" "); sb.append(rs.getString("re_remark")); sb.append(" "); sb.append(rs.getString("rm_name")); sb.append(" "); sb.append(rs.getString("rm_phone")); sb.append("}catch(SQLException e) { e.printStackTrace(); } session.setAttribute("query", sb); response.sendRedirect("Admin/userInfo.jsp"); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } } /** * Servlet implementation class DeleteServlet */ @WebServlet("/DeleteServlet") public class DeleteServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public DeleteServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath());{ String id=rs.getString("he_id"); sb.append(""); } rs.close(); sb.append(" "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" "); sb.append(rs.getString("he_person")); sb.append(" "); sb.append(rs.getString("he_result")); sb.append(" "); sb.append(rs.getString("he_date")); sb.append(" "); sb.append(rs.getString("he_remark")); sb.append(""); }catch(SQLException e) { e.printStackTrace(); } session.setAttribute("query", sb); response.sendRedirect("Admin/healthInfo.jsp"); } } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); "); sb.append("合计"); sb.append(" "); sb.append("优秀:"+String.valueOf(sumInfo[0])+"个"); sb.append(" "); sb.append("良好:"+String.valueOf(sumInfo[1])+"个"); sb.append(" "); sb.append("合格:"+String.valueOf(sumInfo[2])+"个"); sb.append(" "); sb.append("不合格:"+String.valueOf(sumInfo[3])+"个"); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append("StringBuffer sb=new StringBuffer(); try { while(rs.next()) { String id=rs.getString("he_id"); sb.append(""); } rs.close(); sb.append(" "); sb.append(id); sb.append(" "); sb.append(rs.getString("do_section")); sb.append(" "); sb.append(rs.getString("do_number")); sb.append(" "); sb.append(rs.getString("he_person")); sb.append(" "); sb.append(rs.getString("he_result")); sb.append(" "); sb.append(rs.getString("he_date")); sb.append(" "); sb.append(rs.getString("he_remark")); sb.append(""); }catch(SQLException e) { e.printStackTrace(); } HttpSession session=request.getSession(); session.setAttribute("query", sb); response.sendRedirect("Student/healthInfo.jsp"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doPost(request, response); } "); sb.append("合计"); sb.append(" "); sb.append("优秀:"+String.valueOf(sumInfo1[0])+"个"); sb.append(" "); sb.append("良好:"+String.valueOf(sumInfo1[1])+"个"); sb.append(" "); sb.append("合格:"+String.valueOf(sumInfo1[2])+"个"); sb.append(" "); sb.append("不合格:"+String.valueOf(sumInfo1[3])+"个"); sb.append(" "); sb.append(""); sb.append(" "); sb.append(""); sb.append("} /** * Servlet implementation class SQueryHelServlet */ @WebServlet("/SQueryHelServlet") public class SQueryHelServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public SQueryHelServlet() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.getWriter().append("Served at: ").append(request.getContextPath()); response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String section1=request.getParameter("dorSection1"); String section2=request.getParameter("dorSection2"); String number=request.getParameter("dorNumber"); String person=request.getParameter("helPerson"); String result=request.getParameter("helResult"); ResultSet rs=DaoFactory.getHealthInstance().query(section1, section2, number, person, result); int[] sumInfo1=DaoFactory.getHealthInstance().sumInfo1(section1, section2, number, person, result);