基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)

开发工具:eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

							<c:forEach items="${builds}" var="build">
								<option value="${build.id}">${build.name}option>
							c:forEach>
							
						select>
					c:if>
						<select id="searchType" name="searchType" style="width: 80px;">
							<option value="name">姓名option>
							<option value="stuCode">学号option>
							<option value="dormCode">宿舍编号option>
							<option value="sex">性别option>
						select>
						 <input id="keyword" name="keyword" value="${keyword }" type="text"  style="width:120px;height: 30px;" class="input-medium search-query" >
					
					
div>
DOCTYPE html>
<html>
<head>
    <title>title>
    <link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="../css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
head>

<body>
<div class="container">
    <form action="" class="form-horizontal"  role="form">
        <fieldset>
            <legend>Testlegend>
            <div class="form-group">
                <label for="dtp_input1" class="col-md-2 control-label">DateTime Pickinglabel>
                <div class="input-group date form_datetime col-md-5" data-date="1979-09-16T05:25:07Z" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
                    <input class="form-control" size="16" type="text" value="" readonly>
                    <span class="input-group-addon"><span class="glyphicon glyphicon-remove">span>span>
					<span class="input-group-addon"><span class="glyphicon glyphicon-th">span>span>
                div>
				<input type="hidden" id="dtp_input1" value="" /><br/>
			c:if>
		div>
		<form action="student.action?action=save" method="post" onsubmit="return checkForm()">
			<div class="data_form" >
					<div align="center">
						<font id="error" color="red">font>
						<input type="hidden" id="id"  name="id" value="${userUpdate.id}" />
					div>
					<table align="center">
						<tr>
		
		//保存宿舍管理员和宿舍楼的中间表
		dormBuildDao.saveManagerAndBuild(userId,dormBuildIds);
	}
	
	
	@Override
	public List<User> findManager(String searchType, String keyword) {
		StringBuffer  sql = new StringBuffer("SELECT * FROM tb_user WHERE role_id=1 ");
		
		if(keyword != null && !keyword.equals("")) {
			//说明用户是点击搜索按钮进行搜索
			if("name".equals(searchType)) {
				sql.append(" and name like '%"+keyword+"%'");
			}else if("sex".equals(searchType)) {
				sql.append(" and sex = '"+keyword.trim()+"'");
			}else if("tel".equals(searchType)) {
				sql.append(" and tel ="+keyword.trim());
			}
		}
		
			Integer roleId = userCurr.getRoleId();
			List<DormBuild>  builds = new ArrayList<DormBuild>();
			if(roleId.equals(0)) {
				//如当前用户是超级管理员,他能将学生添加到所有的宿舍楼,查询所有宿舍楼
				builds = buildService.findAll();
			}else if(roleId.equals(1)) {
				//如当前用户 为宿舍管理员,他只能添加学生到其管理的宿舍楼
				builds =  buildService.findByUserId(userCurr.getId());
			}
			System.out.println("builds:"+builds);
			request.setAttribute("builds", builds);
			
			String startDate = request.getParameter("startDate");
			String endDate = request.getParameter("endDate");
			String dormBuildId = request.getParameter("dormBuildId");
			String searchType = request.getParameter("searchType");
			String keyword = request.getParameter("keyword");
			String pageIndex = request.getParameter("pageIndex");
			System.out.println("startDate:"+startDate+" endDate:"+endDate+" dormBuildId:"+dormBuildId+
					" searchType:"+searchType+" keyword:"+keyword+"  pageIndex:"+pageIndex);
			
			//默认查询第一页,需两个参数,当前页码pageIndex,每页展示的条数  
			PageModel pageModel = new PageModel();
        <script src="assets/qunit.js">script>
        <script src="assets/qunit-logging.js">script> 
        <script src="assets/coverage.js">script>
        <script src="assets/jquery-1.7.1.min.js">script>
        <script src="../js/bootstrap-datetimepicker.js">script>

        <style>
            .datetimepicker {
                /* Appended to body, abs-pos off the page */
                position: absolute;
                display: none;
                top: -9999em;
                left: -9999em;
            }
					Date date2 = null;
					try {
						date2 = dateFormat.parse(date);
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
					Record record = new Record();
					record.setStudentId(user.getId());
					record.setDate(date2);
	}

	@Override
	public List<User> findManager(String sql) {
		//① 获取连接(数据库地址  用户名 密码)
		Connection  connection = 	ConnectionFactory.getConnection();
		PreparedStatement preparedStatement = null;
		ResultSet  rs = null;
		try {
			//③ 获取集装箱或者说是车
			 preparedStatement = connection.prepareStatement(sql);
			
			//④执行SQL,获取执行后的结果,查询的结果封装在ResultSet
			  rs = preparedStatement.executeQuery();
			
			//因为查询出来的结果包括表头信息,所以要指针下移一行,看是否有查询出来的数据
			//如有数据,就进入循环体,封装该行数据
                top: -9999em;
                left: -9999em;
            }
        style>

        
        <script src="assets/utils.js">script>
        <script src="assets/mock.js">script>

        
        <script src="suites/formats.js">script>
        <script src="suites/mouse_navigation/all.js">script>
        <script src="suites/mouse_navigation/2012.js">script>
					
					response.sendRedirect(getServletContext().getContextPath()+"/record.action?action=list");
				}else {
					//没有添加的权限,跳转到添加页面
					request.setAttribute("error", "您没有添加该学号学生缺勤记录的权限!");
					request.setAttribute("mainRight", "/WEB-INF/jsp/recordAddOrUpdate.jsp");
					request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
				}
			}
			
			
			
		}else if(action != null && action.equals("preUpdate")) {
			preparedStatement.setString(1, user.getName());
			preparedStatement.setString(2, user.getPassWord());
			preparedStatement.setString(3, user.getStuCode());
			preparedStatement.setString(4, user.getDormCode());
			preparedStatement.setString(5, user.getSex());
			preparedStatement.setString(6, user.getTel());
			preparedStatement.setInt(7, user.getDormBuildId());
			preparedStatement.setInt(8, user.getRoleId());
			preparedStatement.setInt(9, user.getCreateUserId());
			
			
			//④执行SQL,获取执行后的结果,查询的结果封装在ResultSet
			 preparedStatement.executeUpdate();
			
			 /*resultSet = preparedStatement.getGeneratedKeys();
			resultSet.next();
			
			Integer id = resultSet.getInt(1);*/
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			ConnectionFactory.close(connection, preparedStatement, resultSet);
				" LEFT JOIN tb_dormbuild  build ON build.`id` = user.dormBuildId "
				+ " where user.role_id = 2");
		
		
		if(keyword != null && !keyword.equals("") && "name".equals(searchType)) {
			//根据名字查询
			sql.append("  and  user.name like '%"+keyword.trim()+"%'");
			
		}else if(keyword != null && !keyword.equals("") && "stuCode".equals(searchType)) {
			//根据学号查询
			sql.append(" and user.stu_code = '"+keyword.trim()+"'");
			
		}else if(keyword != null && !keyword.equals("") && "dormCode".equals(searchType)) {
			//根据宿舍编号查询
			sql.append(" and user.dorm_code = '"+keyword.trim()+"'");
	//文档加载完成后
	window.onload = function(){
		//获取当前要修改的学生居中的宿舍楼id
		var studentBuildId = "${userUpdate.dormBuildId}";
		
		var dormBuildIdSelect = document.getElementById("dormBuildId");
		var options = dormBuildIdSelect.options;
		
		//遍历所有的option,如果option中的值=学生居中的宿舍楼id,则该option被选中
		$.each(options,function(i,option){
			$(option).attr("selected",option.value == studentBuildId);
			//查询处理的考勤记录时间要小于查询的结束时间
			sql.append(" and record.date <= '"+endDate+"'");
		}
		
		//获取当前登录用户的角色
		Integer roleId = userCurr.getRoleId();
		if(roleId != null && roleId.equals(1)) {
			//当前登录用户是宿舍管理员
			//获取当前宿舍管理员管理的所有宿舍楼
			List<DormBuild>  builds  = dormBuildDao.findByUserId(userCurr.getId());
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 1,
		minView: 0,
		maxView: 1,
		forceParse: 0
    });
script>

body>
html>
DOCTYPE html>
<html>
				build.setName(rs.getString("name"));
				build.setDisabled(rs.getInt("disabled"));
				build.setRemark(rs.getString("remark"));
				
				return build;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			ConnectionFactory.close(connection, preparedStatement, rs);
		}
		return null;
	}

	@Override
			
			//④执行SQL,更新
			ResultSet rs =  preparedStatement.executeQuery();
			List<Record> records = new ArrayList<Record>();
			
			while (rs.next()) {
				Record record = new Record();
				record.setId(rs.getInt("recordId"));
				record.setDate(rs.getTimestamp("date"));
				record.setRemark(rs.getString("remark"));
				record.setDisabled(rs.getInt("recordDisabled"));
				
				User user = new User();
				user.setId(rs.getInt("student_id"));
				user.setCreateUserId(rs.getInt("create_user_id"));
				user.setDormBuildId(rs.getInt("dormBuildId"));
				user.setDormCode(rs.getString("dorm_Code"));
				user.setName(rs.getString("name"));
				user.setPassWord(rs.getString("passWord"));
				user.setRoleId(rs.getInt("role_id"));
				user.setSex(rs.getString("sex"));
				user.setStuCode(rs.getString("stu_code"));
				user.setTel(rs.getString("tel"));
			
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			ConnectionFactory.close(connection, preparedStatement, rs);
		}
		return null;
	}

	@Override
	public User findById(int id) {
			request.setAttribute("mainRight", "/WEB-INF/jsp/recordList.jsp");
			request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
			
		}else if(action != null && action.equals("preAdd")) {
			//跳转到添加页面
			request.setAttribute("mainRight", "/WEB-INF/jsp/recordAddOrUpdate.jsp");
			request.getRequestDispatcher("/WEB-INF/jsp/main.jsp").forward(request, response);
			
		}else if(action != null && action.equals("save")) {
			//保存
			String stuCode = request.getParameter("stuCode");
			String date = request.getParameter("date");
			String remark = request.getParameter("remark");
			System.out.println("remark:"+remark+"  date:"+date+"  stuCode:"+stuCode);
					
					
					 <button type="submit" class="btn btn-info" onkeydown="if(event.keyCode==13) myForm.submit()">搜索button>
				span>
		form>
		<div>
			<table class="table table-striped table-bordered table-hover datatable">
				<thead>
					<tr>
					<th>日期th>
					<th>学号th>
					<th>姓名th>
					<th>性别th>
					<th>宿舍楼th>
					<th>寝室th>
			//③ 获取集装箱或者说是车
			 preparedStatement = connection.prepareStatement(sql);
			
			//④执行SQL,获取执行后的结果,查询的结果封装在ResultSet
			  rs = preparedStatement.executeQuery();
			
			//因为查询出来的结果包括表头信息,所以要指针下移一行,看是否有查询出来的数据
			//如有数据,就进入循环体,封装该行数据
			  List<User> users = new ArrayList<User>();
			while (rs.next()) {
				User user = new User();
				//每一行的数据封装在一个实体bean中,根据字段名获取字段值,注意该字段是什么类型,就get什么类型
				user.setId(rs.getInt("id"));
				user.setCreateUserId(rs.getInt("create_user_id"));
				user.setDisabled(rs.getInt("disabled"));
				user.setName(rs.getString("name"));
				user.setPassWord(rs.getString("passWord"));
				user.setRoleId(rs.getInt("role_id"));
				user.setSex(rs.getString("sex"));
				user.setStuCode(rs.getString("stu_code"));
				user.setTel(rs.getString("tel"));
						<tr>
							<td><font color="red">*font>性别:td>
							<td>
								<select id="sex" name="sex" style="width: 90px;">
									<option value="" ${user.sex eq "男" ? "selected" : ''}>option>
									<option value="" ${user.sex eq "女" ? "selected" : ''}>option>
								select>
							td>
						tr>
						<tr>
							<td><font color="red">*font>联系电话:td>
							<td><input type="text" id="tel"  name="tel" value="${user.tel}"  style="margin-top:5px;height:30px;" />td>
						tr>
						<tr>
							<td><font color="red">*font>管理楼栋:td>
		request.setCharacterEncoding("utf-8");
		String action = request.getParameter("action");
		//通过request.getParameter("id")方式获取的值都是String类型
		String id = request.getParameter("id");
		System.out.println("action:"+action);
		
		DormBuildService dormBuildService = new DormBuildServiceImpl();
		
		if(action != null & action.equals("list")) {
			List<DormBuild>  builds = new ArrayList<DormBuild>();
							<option value="dormCode">宿舍编号option>
							<option value="sex">性别option>
						select>
						 <input id="keyword" name="keyword" value="${keyword }" type="text"  style="width:120px;height: 30px;" class="input-medium search-query" >
					
					
					 <button type="submit" class="btn btn-info" onkeydown="if(event.keyCode==13) myForm.submit()">搜索button>
				span>
		form>
		<div>
			<table class="table table-striped table-bordered table-hover datatable">
				<thead>
					<tr>
			chain.doFilter(httpServletRequest, response);
		}else {
			httpServletRequest.getRequestDispatcher("/index.jsp").forward(httpServletRequest, response);
		}
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
package com.demo.service;

import java.util.List;

import com.demo.bean.DormBuild;
import com.demo.bean.Record;
				user.setName(rs.getString("name"));
				user.setPassWord(rs.getString("passWord"));
				user.setRoleId(rs.getInt("role_id"));
				user.setSex(rs.getString("sex"));
				user.setStuCode(rs.getString("stu_code"));
				user.setTel(rs.getString("tel"));
				user.setDormCode(rs.getString("dorm_code"));
				user.setDormBuildId(rs.getInt("dormBuildId"));
				
				DormBuild build = new DormBuild();
				build.setId(rs.getInt("dormBuildId"));
				build.setName(rs.getString("buildName"));
				build.setRemark(rs.getString("remark"));
				user.setDormBuild(build);
				
				users.add(user);
			}
			
			return users;
		} catch (SQLException e) {
				userService.updateManager(user);
				
				//修改还需修改宿舍管理员与宿舍楼的中间表
				//① 删除当前宿舍管理员管理的所有宿舍楼
				buildService.deleteByUserId(user.getId());
				
				//② 新增当前宿舍管理员管理的所有宿舍楼  
				buildService.saveManagerAndBuild(user.getId(),dormBuildIds);
			}
			//跳转到宿舍管理员列表页,查看所有的宿舍管理员
			//重定向,请求链断开,不能在下一个servlet或jsp中获取保存在request中的参数
			response.sendRedirect(getServletContext().getContextPath()+"/dormManager.action?action=list");
		
		}else if(action != null & action.equals("preUpdate")) {
			//跳转到修改宿舍管理员的页面
			
			//根据宿舍管理员ID,获取宿舍管理员
			User user = userService.findById(Integer.parseInt(id));
			//根据宿舍管理员ID获取宿舍管理员管理的楼栋
			List<DormBuild> userBuilds = buildService.findByUserId(user.getId());
			user.setDormBuilds(userBuilds);
			System.out.println("user:"+user);
			
					<table align="center">
						<tr>
							<td><font color="red">*font>学号:td>
							<td><input type="text" id="stuCode"  name="stuCode" value="${userUpdate.stuCode}"  style="margin-top:5px;height:30px;" />td>
						tr>
						<tr>
							<td><font color="red">*font>姓名:td>
							<td><input type="text" id="name"  name="name" value="${userUpdate.name}"  style="margin-top:5px;height:30px;" />td>
						tr>
						<tr>
							<td><font color="red">*font>性别:td>
							<td>
								<select id="sex" name="sex" style="width: 90px;">
									

运行环境

Java≥8、Tomcat≥8.0、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

超级管理员:登录退出、宿舍管理员管理、学生管理、宿舍楼管理、缺勤管理、修改密码

宿舍管理员:登录退出、学生管理、缺勤管理

学生:登录退出、缺勤查看

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第1张图片

超级管理员

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第2张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第3张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第4张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第5张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第6张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第7张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第8张图片

宿舍管理员

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第9张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第10张图片

学生

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第11张图片

基于javaweb+JSP+Servlet宿舍管理系统(超级管理员、宿舍管理员、学生)_第12张图片


↖[获取源码方式]见左侧

你可能感兴趣的:(javaweb,jsp,mysql,servlet,jdbc)