作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
本项目包含系统管理员、楼宇管理员、学生三种角色;
系统管理员角色包含以下功能:
登录页面,楼宇管理员管理,学生管理,楼宇管理,宿舍管理,入住登记,寝室调换,迁出登记,缺寝记录,迁出记录等功能。
楼宇管理员角色包含以下功能:
登录页面,学生管理,缺勤记录查询等功能。
学生角色包含以下功能:
登录页面,查看缺勤记录等功能。
环境需要
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项目: 否;
技术栈
1. 后端:servlet+struts
2. 前端:JSP+css+javacript
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中src/com/db/DBHelper.java配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入http://localhost:8080/ 登录
系统管理员账号/密码:admin/admin
楼宇管理员账号/密码:louyu/123456
学生账号/密码: 001/123456
运行截图
相关代码
AdminLog
package com.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.dao.*;
public class AdminLog extends ActionSupport {
//ÏÂÃæÊÇActionÄÚÓÃÓÚ·â×°Óû§ÇëÇó²ÎÊýµÄÊôÐÔ
private List<BuildingBean> buildinglist;
private List<DomitoryBean> domitorylist;
public List<BuildingBean> getBuildinglist() {
return buildinglist;
}
public void setBuildinglist(List<BuildingBean> buildinglist) {
this.buildinglist = buildinglist;
}
public List<DomitoryBean> getDomitorylist() {
return domitorylist;
}
public void setDomitorylist(List<DomitoryBean> domitorylist) {
this.domitorylist = domitorylist;
}
private String BuildingID;
private String DomitoryID;
public String getBuildingID() {
return BuildingID;
}
public void setBuildingID(String buildingID) {
BuildingID = buildingID;
}
public String getDomitoryID() {
return DomitoryID;
}
public void setDomitoryID(String domitoryID) {
DomitoryID = domitoryID;
}
//´¦ÀíÓû§ÇëÇóµÄexecute·½·¨
public String execute() throws Exception {
//½â¾öÂÒÂ룬ÓÃÓÚÒ³ÃæÊä³ö
HttpServletResponse response=null;
response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//´´½¨session¶ÔÏó
HttpSession session = ServletActionContext.getRequest().getSession();
//ÑéÖ¤ÊÇ·ñÕý³£µÇ¼
if(session.getAttribute("id")==null){
out.print("<script language='javascript'>alert('ÇëÖØеǼ£¡');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}
//²éѯ¥Óî
buildinglist=new BuildingDao().GetList("","Building_Name");
// System.out.println(BuildingID);
//²éѯÌõ¼þ
String strWhere="1=1 ";
if(!(isInvalid(BuildingID)))
{
strWhere+=" and Domitory_BuildingID='"+BuildingID+"'";
}
else{
strWhere+=" and 1=2";
}
//²éѯÇÞÊÒ
domitorylist=new DomitoryDao().GetList(strWhere,"Domitory_Name");
return SUCCESS;
}
//ÅжÏÊÇ·ñ¿ÕÖµ
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
//²âÊÔ
public static void main(String[] args) {
System.out.println();
}
}
AdminLogList
package com.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.dao.*;
public class BuildingAddSave extends ActionSupport {
//下面是Action内用于封装用户请求参数的属性
private String Building_Name ;
private String Building_Introduction ;
public String getBuilding_Name() {
return Building_Name;
}
public void setBuilding_Name(String buildingName) {
Building_Name = buildingName;
}
public String getBuilding_Introduction() {
return Building_Introduction;
}
public void setBuilding_Introduction(String buildingIntroduction) {
Building_Introduction = buildingIntroduction;
}
//处理用户请求的execute方法
public String execute() throws Exception {
//解决乱码,用于页面输出
HttpServletResponse response=null;
response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//创建session对象
HttpSession session = ServletActionContext.getRequest().getSession();
//验证是否正常登录
if(session.getAttribute("id")==null){
out.print("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}
//查询名称是否存在
List<BuildingBean> list=new BuildingDao().GetList("Building_Name='"+Building_Name+"'", "");
if(list.size()>0)
{
out.print("<script language='javascript'>alert('名称已经存在!');history.back(-1);</script>");
out.flush();out.close();return null;
}
//添加
BuildingBean cnbean=new BuildingBean();
cnbean.setBuilding_Name(Building_Name);
cnbean.setBuilding_Introduction(Building_Introduction);
new BuildingDao().Add(cnbean);
//跳转
out.print("<script language='javascript'>alert('添加成功!');window.location='BuildingManager.action';</script>");
out.flush();out.close();return null;
}
//判断是否空值
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
//测试
public static void main(String[] args) {
System.out.println();
}
}
BuildingManager
package com.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.dao.*;
public class BuildingManager extends ActionSupport {
//下面是Action内用于封装用户请求参数的属性
private List<BuildingBean> list;
public List<BuildingBean> getList() {
return list;
}
public void setList(List<BuildingBean> list) {
this.list = list;
}
private String SearchKey;
public String getSearchKey() {
return SearchKey;
}
public void setSearchKey(String searchKey) {
SearchKey = searchKey;
}
//处理用户请求的execute方法
public String execute() throws Exception {
//解决乱码,用于页面输出
HttpServletResponse response=null;
response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//创建session对象
HttpSession session = ServletActionContext.getRequest().getSession();
//验证是否正常登录
if(session.getAttribute("id")==null){
out.print("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}
//查询条件
String strWhere="1=1";
if(!(isInvalid(SearchKey)))
{
strWhere+=" and Building_Name='"+SearchKey+"'";
}
//查询所有
list=new BuildingDao().GetList(strWhere,"Building_Name");
return SUCCESS;
}
//判断是否空值
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
//测试
public static void main(String[] args) {
System.out.println();
}
}
BuildingUpdate
package com.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.dao.*;
public class BuildingUpdate extends ActionSupport {
//下面是Action内用于封装用户请求参数的属性
private String Building_ID;
private BuildingBean cnbean;
public String getBuilding_ID() {
return Building_ID;
}
public void setBuilding_ID(String studentID) {
Building_ID = studentID;
}
public BuildingBean getCnbean() {
return cnbean;
}
public void setCnbean(BuildingBean cnbean) {
this.cnbean = cnbean;
}
//处理用户请求的execute方法
public String execute() throws Exception {
//解决乱码,用于页面输出
HttpServletResponse response=null;
response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//创建session对象
HttpSession session = ServletActionContext.getRequest().getSession();
//验证是否正常登录
if(session.getAttribute("id")==null){
out.print("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}
//查询
cnbean=new BuildingDao().GetBean(Integer.parseInt(Building_ID));
return SUCCESS;
}
//判断是否空值
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
//测试
public static void main(String[] args) {
System.out.println();
}
}
DomitoryAdd
package com.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.dao.*;
public class DomitoryAdd extends ActionSupport {
//下面是Action内用于封装用户请求参数的属性
private List<BuildingBean> list;
public List<BuildingBean> getList() {
return list;
}
public void setList(List<BuildingBean> list) {
this.list = list;
}
//处理用户请求的execute方法
public String execute() throws Exception {
//解决乱码,用于页面输出
HttpServletResponse response=null;
response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//创建session对象
HttpSession session = ServletActionContext.getRequest().getSession();
//验证是否正常登录
if(session.getAttribute("id")==null){
out.print("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}
//查询所有楼宇
list=new BuildingDao().GetList("","Building_Name");
return SUCCESS;
}
//判断是否空值
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
//测试
public static void main(String[] args) {
System.out.println();
}
}
DomitoryAddSave
package com.action;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.dao.*;
public class DomitoryAddSave extends ActionSupport {
//下面是Action内用于封装用户请求参数的属性
private String Domitory_BuildingID ;
private String Domitory_Name ;
private String Domitory_Type ;
private String Domitory_Number ;
private String Domitory_Tel ;
public String getDomitory_BuildingID() {
return Domitory_BuildingID;
}
public void setDomitory_BuildingID(String domitoryBuildingID) {
Domitory_BuildingID = domitoryBuildingID;
}
public String getDomitory_Name() {
return Domitory_Name;
}
public void setDomitory_Name(String domitoryName) {
Domitory_Name = domitoryName;
}
public String getDomitory_Type() {
return Domitory_Type;
}
public void setDomitory_Type(String domitoryType) {
Domitory_Type = domitoryType;
}
public String getDomitory_Number() {
return Domitory_Number;
}
public void setDomitory_Number(String domitoryNumber) {
Domitory_Number = domitoryNumber;
}
public String getDomitory_Tel() {
return Domitory_Tel;
}
public void setDomitory_Tel(String domitoryTel) {
Domitory_Tel = domitoryTel;
}
//处理用户请求的execute方法
public String execute() throws Exception {
//解决乱码,用于页面输出
HttpServletResponse response=null;
response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
//创建session对象
HttpSession session = ServletActionContext.getRequest().getSession();
//验证是否正常登录
if(session.getAttribute("id")==null){
out.print("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}
//查询是否存在
List<DomitoryBean> list=new DomitoryDao().GetList("Domitory_Name='"+Domitory_Name+"' and Domitory_BuildingID="+Domitory_BuildingID, "");
if(list.size()>0)
{
out.print("<script language='javascript'>alert('该楼宇中已经存在该寝室号!');history.back(-1);</script>");
out.flush();out.close();return null;
}
//添加
DomitoryBean cnbean=new DomitoryBean();
cnbean.setDomitory_BuildingID(Integer.parseInt(Domitory_BuildingID));
cnbean.setDomitory_Name(Domitory_Name);
cnbean.setDomitory_Type(Domitory_Type);
cnbean.setDomitory_Number(Domitory_Number);
cnbean.setDomitory_Tel(Domitory_Tel);
new DomitoryDao().Add(cnbean);
//跳转
out.print("<script language='javascript'>alert('添加成功!');window.location='DomitoryManager.action';</script>");
out.flush();out.close();return null;
}
//判断是否空值
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
//测试
public static void main(String[] args) {
System.out.println();
}
}
GoLogin
package com.action;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.dao.*;
import com.bean.*;
import com.opensymphony.xwork2.ActionSupport;
public class GoLogin extends ActionSupport {
//下面是Action内用于封装用户请求参数的属性
private String Type;
private String Username;
private String Password;
private String Msg;
public String getType() {
return Type;
}
public void setType(String type) {
Type = type;
}
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public String getMsg() {
return Msg;
}
public void setMsg(String msg) {
Msg = msg;
}
//处理用户请求的execute方法
public String execute() throws Exception {
if(Type.equals("系统管理员"))
{
if (null == new AdminDao().CheckLogin(Username, Password)) {
Msg = "用户名或者密码错误";
return INPUT;
}
else
{
//获取ID
String Admin_ID=new AdminDao().CheckLogin(Username, Password);
//创建session
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("id", Admin_ID);
session.setAttribute("type", "1");
return SUCCESS;
}
}
else if(Type.equals("楼宇管理员"))
{
if (null == new TeacherDao().CheckLogin(Username, Password)) {
Msg = "用户名或者密码错误";
return INPUT;
}
else
{
//获取ID
String Teacher_ID=new TeacherDao().CheckLogin(Username, Password);
//创建session
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("id", Teacher_ID);
session.setAttribute("type", "2");
return SUCCESS;
}
}
else if(Type.equals("学生"))
{
if (null == new StudentDao().CheckLogin(Username, Password)) {
Msg = "用户名或者密码错误";
return INPUT;
}
else
{
//获取ID
String Student_ID=new StudentDao().CheckLogin(Username, Password);
//创建session
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("id", Student_ID);
session.setAttribute("type", "3");
return SUCCESS;
}
}
else
{
Msg = "身份类型错误";
return INPUT;
}
}
}
如果也想学习本系统,下面领取。关注并回复:117jsp