系统一共分为3个角色分别是:管理员,学生,宿管
难度等级:✩✩✩
用户类型:三角色(管理员,学生,宿管)
设计模式:MVC
项目架构:B/S架构
开发语言:Java语言
前端技术:layui、HTML、CSS、JS、JQuery等
后端技术:JSP、servlet框架
运行环境:Windows7或10、JDK1.8
运行工具:本系统采用Eclipse开发,仅支持Eclipse运行,不支持MyEclipse和IDEA运行,因为三者的骨架不一样,强行导入打开运行可能会导致出现未知的错误。(如若想用idea运行,需要转换!!!!)
数 据 库:MySQL5.5/5.7/8.0版本
运行服务器:Tomcat7.0/8.0/8.5/9.0等版本
是否基于Maven环境:否
是否采用框架:是
数据库表数量:6张表
JSP页面数量:20多张
是否有分页:有分页
基于javaweb宿舍管理系统(eclipse
项目结构
数据库结构
登录注册
学生管理
宿舍管理
公告管理
缺勤管理
登录代码
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
宿 舍 管 理 系 统
package edu.school.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import edu.school.entity.Admin;
import edu.school.entity.Dormitory;
import edu.school.entity.Student;
import edu.school.entity.User;
import edu.school.service.LoginService;
import edu.school.service.impl.LoginServiceImpl;
import edu.school.service.impl.StudentServiceImpl;
public class LoginServlet extends HttpServlet{
private LoginService service = new LoginServiceImpl();
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action=request.getParameter("action");//接受请求的参数
if(action != null && action.equals("toLogin")) {//去登录页面
toLogin(request, response);
}else if(action != null && action.equals("login")) {//登录
login(request, response);
}else if(action != null && action.equals("LoginOutAct")) {//退出
LoginOutAct(request, response);
}else if(action != null && action.equals("welcome")) {//默认页面
welcome(request, response);
}else if(action != null && action.equals("toRegister")) {//去注册
toRegister(request, response);
}
}
private void toRegister(HttpServletRequest request,
HttpServletResponse response) {
try {
List dormitoryList = new StudentServiceImpl().selectList();
request.setAttribute("dormitoryList", dormitoryList);
request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}
}
private void welcome(HttpServletRequest request,
HttpServletResponse response) {
try {
request.getRequestDispatcher("/WEB-INF/views/console.jsp").forward(request,response);
} catch (Exception e) {
e.printStackTrace();
}
}
private void LoginOutAct(HttpServletRequest request,
HttpServletResponse response) {
try {
request.getSession().removeAttribute("admin");
request.getSession().removeAttribute("student");
request.getSession().removeAttribute("user");
request.getSession().removeAttribute("flag");
response.sendRedirect(request.getContextPath()+"/LoginServlet?action=toLogin");
} catch (Exception e) {
e.printStackTrace();
}
}
private void login(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
removeAll(request,response);
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String type = request.getParameter("type");
if(type.equals("1")){
Admin admin = new Admin();
admin.setUsername(userName);
admin.setPwd(password);
Admin admin1 = service.selectAdmin(admin);
try {
if (admin1 == null){
request.setAttribute("message", "管理员用户不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("admin",admin1);
request.getSession().setAttribute("flag",1);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if(type.equals("2")){
Student student = new Student();
student.setStuno(userName);
student.setPwd(password);
Student student1 = service.selectStudent(student);
try {
if (student1 == null){
request.setAttribute("message", "学号不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("student",student1);
request.getSession().setAttribute("flag",2);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if(type.equals("3")){
User user = service.selectUser(userName,password);
try {
if (user == null){
request.setAttribute("message", "用户名不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("user",user);
request.getSession().setAttribute("flag",3);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else{
request.setAttribute("message", "账号不存在或者密码错误");
try {
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void removeAll(HttpServletRequest request,
HttpServletResponse response) {
request.getSession().removeAttribute("admin");
request.getSession().removeAttribute("student");
request.getSession().removeAttribute("user");
request.getSession().removeAttribute("flag");
}
private void toLogin(HttpServletRequest request,
HttpServletResponse response) {
try {
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}catch(Exception e){
e.printStackTrace();
}
return;
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>