目录结构:

连接数据库功能代码实现:

package com.db;

import java.sql.*;

public class DBHelper {
private String dbUrl="jdbc:mysql://localhost:3306/sushe";
private String dbUser="root";
private String dbPassword="123456";
private String jdbcName="com.mysql.jdbc.Driver";
public Connection getConn(){
Connection conn = null;
try{
Class.forName(jdbcName);
}
catch(Exception e){}
try{
conn=DriverManager.getConnection(dbUrl,dbUser,dbPassword);
}
catch(SQLException ex){}
return conn;
}
public static void main(String[] args)
{
System.out.println(new DBHelper().getConn());

}

}

登陆功能代码实现:

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 PasswordUpdateSave extends ActionSupport {

//下面是Action内用于封装用户请求参数的属性
private String Password;
private String Password2;
private String Msg;
public String getPassword() {
return Password;
}

public void setPassword(String password) {
Password = password;
}

public String getPassword2() {
return Password2;
}

public void setPassword2(String password2) {
Password2 = password2;
}

public String getMsg() {
return Msg;
}

public void setMsg(String msg) {
Msg = msg;
}

//处理用户请求的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("");
out.flush();out.close();return null;
}
String type=session.getAttribute("type").toString();
if(type.equals("1"))//校园管理员身份
{
//查询原密码是否正确
if (new AdminDao().CheckPassword(session.getAttribute("id").toString(), Password)) {
//修改密码
AdminBean cnbean=new AdminBean();
cnbean=new AdminDao().GetBean(Integer.parseInt(session.getAttribute("id").toString()));
cnbean.setAdmin_Password(Password2);
new AdminDao().Update(cnbean);
out.print("");
out.flush();out.close();return null;
}
else
{
Msg = "用户名或者密码错误";
return INPUT;
}
}
else if(type.equals("2"))//楼宇管理员身份
{
//查询原密码是否正确
if (new TeacherDao().CheckPassword(session.getAttribute("id").toString(), Password)) {
//修改密码
TeacherBean cnbean=new TeacherBean();
cnbean=new TeacherDao().GetBean(Integer.parseInt(session.getAttribute("id").toString()));
cnbean.setTeacher_Password(Password2);
new TeacherDao().Update(cnbean);
out.print("");
out.flush();out.close();return null;
}
else
{
Msg = "用户名或者密码错误";
return INPUT;
}
}
else if(type.equals("3"))//学生身份
{
//查询原密码是否正确
if (new StudentDao().CheckPassword(session.getAttribute("id").toString(), Password)) {
//修改密码
StudentBean cnbean=new StudentBean();
cnbean=new StudentDao().GetBean(Integer.parseInt(session.getAttribute("id").toString()));
cnbean.setStudent_Password(Password2);
new StudentDao().Update(cnbean);
out.print("");
out.flush();out.close();return null;
}
else
{
Msg = "用户名或者密码错误";
return INPUT;
}
}
else
{
out.print("");
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();
}

}

添加宿舍管理员功能代码实现:

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 TeacherAddSave extends ActionSupport {

//下面是Action内用于封装用户请求参数的属性
private String Teacher_Username ;
private String Teacher_Password ;
private String Teacher_Name ;
private String Teacher_Sex ;
private String Teacher_Tel ;
public String getTeacher_Username() {
return Teacher_Username;
}

public void setTeacher_Username(String cookUsername) {
Teacher_Username = cookUsername;
}

public String getTeacher_Password() {
return Teacher_Password;
}

public void setTeacher_Password(String cookPassword) {
Teacher_Password = cookPassword;
}

public String getTeacher_Name() {
return Teacher_Name;
}

public void setTeacher_Name(String cookName) {
Teacher_Name = cookName;
}

public String getTeacher_Sex() {
return Teacher_Sex;
}

public void setTeacher_Sex(String cookSex) {
Teacher_Sex = cookSex;
}

public String getTeacher_Tel() {
return Teacher_Tel;
}

public void setTeacher_Tel(String cookTel) {
Teacher_Tel = cookTel;
}

//处理用户请求的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("");
out.flush();out.close();return null;
}

//查询用户名是否存在
List list=new TeacherDao().GetList("Teacher_Username='"+Teacher_Username+"'", "");
if(list.size()>0)
{
out.print("");
out.flush();out.close();return null;
}
//添加
TeacherBean cnbean=new TeacherBean();
cnbean.setTeacher_Username(Teacher_Username);
cnbean.setTeacher_Password(Teacher_Password);
cnbean.setTeacher_Name(Teacher_Name);
cnbean.setTeacher_Sex(Teacher_Sex);
cnbean.setTeacher_Tel(Teacher_Tel);
new TeacherDao().Add(cnbean);

//跳转
out.print("");
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();
}

}

学生迁出登记功能实现代码:

package com.action;

import java.io.PrintWriter;
import java.util.Calendar;
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 StudentQCSave extends ActionSupport {

//下面是Action内用于封装用户请求参数的属性
private String Student_ID ;
private String Out_Remark ;
public String getOut_Remark() {
return Out_Remark;
}

public void setOut_Remark(String outRemark) {
Out_Remark = outRemark;
}

public String getStudent_ID() {
return Student_ID;
}

public void setStudent_ID(String studentID) {
Student_ID = studentID;
}

//处理用户请求的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("");
out.flush();out.close();return null;
}

//修改学生状态
StudentBean cnbean=new StudentBean();
cnbean=new StudentDao().GetBean(Integer.parseInt(Student_ID));
cnbean.setStudent_State("迁出");
new StudentDao().Update(cnbean);

//添加迁出记录
OutBean outbean=new OutBean();
outbean.setOut_StudentID(Integer.parseInt(Student_ID));
outbean.setOut_Date(getNowdate());
outbean.setOut_Remark(Out_Remark);

new OutDao().Add(outbean);

//跳转
out.print("");
out.flush();out.close();return null;

}
//获取当前日期
public String getNowdate(){
Calendar c=Calendar.getInstance();
c.add(Calendar.MONTH, 1);
int year=c.get(Calendar.YEAR);
int month=c.get(Calendar.MONTH);
int date=c.get(Calendar.DATE);
return year+"-"+month+"-"+date;
}
//判断是否空值
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}

//测试
public static void main(String[] args) {
System.out.println();
}

}

登陆后界面部分代码:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>








系统选项










<%if(session.getAttribute("type").toString().equals("1")){%>






















































<%}%>
<%if(session.getAttribute("type").toString().equals("2")){%>












<%}%>
<%if(session.getAttribute("type").toString().equals("3")){%>






<%}%>









后台首页
楼宇管理员管理
学生管理
楼宇管理
宿舍管理
学生入住登记
学生寝室调换
学生迁出登记
学生缺寝记录
迁出记录
学生管理
学生缺寝记录
我的缺寝记录
修改密码
退出系统

学生入住界面代码实现:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>



校园宿舍管理系统




















校园宿舍管理系统
 






<%@ include file="Left.jsp"%>







学生入住登记






















  
楼宇:
寝室:
*学生学号:
 

 



学生缺勤登记界面代码实现:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>



校园宿舍管理系统





















校园宿舍管理系统
 






<%@ include file="Left.jsp"%>







学生缺寝登记






































请仔细确认信息是否正确,缺寝登记提交后将不可修改!
学号:

姓名:
性别:
班级:
寝室:
*缺寝日期:
缺寝备注:
 
  

 




————————————————