宿舍管理系统部分代码实现

目录结构:

 

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

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("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
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("<script language='javascript'>alert('修改成功!');window.location='PasswordUpdate.jsp';</script>");
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("<script language='javascript'>alert('修改成功!');window.location='PasswordUpdate.jsp';</script>");
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("<script language='javascript'>alert('修改成功!');window.location='PasswordUpdate.jsp';</script>");
out.flush();out.close();return null;
}
else
{
Msg = "用户名或者密码错误";
return INPUT;
}
}
else
{
out.print("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</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();
}

}

 

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

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("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
out.flush();out.close();return null;
}

//查询用户名是否存在
List<TeacherBean> list=new TeacherDao().GetList("Teacher_Username='"+Teacher_Username+"'", "");
if(list.size()>0)
{
out.print("<script language='javascript'>alert('用户名已经存在!');history.back(-1);</script>");
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("<script language='javascript'>alert('添加成功!');window.location='TeacherManager.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();
}

}

 

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

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("<script language='javascript'>alert('请重新登录!');window.location='Login.jsp';</script>");
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("<script language='javascript'>alert('学生迁出操作成功!');window.location='StudentTH.jsp';</script>");
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"%>
<link href="Style/Style.css" rel="stylesheet" type="text/css" />
<table width="155" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="31" align="center" background="Images/left1.jpg"><strong>系统选项</strong></td>
</tr>
<tr>
<td height="50" align="center" valign="top"><table width="150" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="Index.jsp">后台首页</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<%if(session.getAttribute("type").toString().equals("1")){%>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="TeacherManager.action">楼宇管理员管理</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="StudentManager.action">学生管理</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="BuildingManager.action">楼宇管理</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="DomitoryManager.action">宿舍管理</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="StudentRZ.action">学生入住登记</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="StudentTH.jsp">学生寝室调换</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="StudentQC.jsp">学生迁出登记</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="AdminLog.action">学生缺寝记录</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="OutList.action">迁出记录</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<%}%>
<%if(session.getAttribute("type").toString().equals("2")){%>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="MyStudent.action">学生管理</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="MyLog.action">学生缺寝记录</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<%}%>
<%if(session.getAttribute("type").toString().equals("3")){%>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="StudentLog.action">我的缺寝记录</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<%}%>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="PasswordUpdate.jsp">修改密码</a></td>
</tr>
<tr>
<td height="5" align="center"><img src="Images/ic.gif" width="1" height="1"></td>
</tr>
<tr>
<td height="30" align="center" background="Images/left2.jpg" style="text-align:left; padding-left:40px;"><a href="Quit.action" onclick="return confirm('确定要退出系统吗?')">退出系统</a></td>
</tr>
</table>
</td>
</tr>
</table>

 

学生入住界面代码实现:

<%@ 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"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>校园宿舍管理系统</title>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="Style/Style.css" rel="stylesheet" type="text/css" />
</head>
<script language="JavaScript">


function mycheck(){

if(isNull(form1.Building_ID.value)){
alert("请选择楼宇!");
return false;
}
if(isNull(form1.Domitory_ID.value)){
alert("请选择寝室!");
return false;
}
if(isNull(form1.Student_Username.value)){
alert("请输入学生学号!");
return false;
}

}

function isNull(str){
if ( str == "" ) return true;
var regu = "^[ ]+$";
var re = new RegExp(regu);
return re.test(str);
}


</script>
<body>
<center>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="60" bgcolor="#E6F5FF" style="color:#06F; font-size:19px; font-weight:bolder; padding-left:50px;">校园宿舍管理系统</td>
</tr>
<tr>
<td height="30" background="Images/MenuBg.jpg">&nbsp;</td>
</tr>
<tr>
<td height="500" align="center" valign="top"><table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="191" height="500" align="center" valign="top" background="Images/leftbg.jpg">
<%@ include file="Left.jsp"%>
</td>
<td width="709" align="center" valign="top" bgcolor="#F6F9FE"><table width="709" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" background="Images/mainMenuBg.jpg" style="padding-left:25px;">学生入住登记</td>
</tr>
<tr>
<td height="470" align="center" valign="top" bgcolor="#F6F9FE"><form name="form1" method="post" action="StudentRZSave.action" onSubmit="return mycheck()" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" height="30" align="right">&nbsp;</td>
<td width="67%">&nbsp;</td>
</tr>
<tr>
<td height="30" align="right"><span style="color:red;">*</span>楼宇:</td>
<td><select name="Building_ID" id="Building_ID" onChange="javascript:window.location='StudentRZ.action?BuildingID='+this.value;">
<option value="">请选择</option>
<s:iterator value="buildinglist">
<option value="${Building_ID}" <s:if test="BuildingID==Building_ID">selected</s:if>>${Building_Name}</option>
</s:iterator>
</select></td>
</tr>
<tr>
<td height="30" align="right"><span style="color:red;">*</span>寝室:</td>
<td><select name="Domitory_ID" id="Domitory_ID">
<option value="">请选择</option>
<s:iterator value="domitorylist">
<option value="${Domitory_ID}">${Domitory_Name}</option>
</s:iterator>
</select></td>
</tr>
<tr>
<td height="30" align="right"><span style="color:red;">*</span>学生学号:</td>
<td><label for="Student_ID"></label>
<input type="text" name="Student_Username" id="Student_Username"></td>
</tr>
<tr>
<td height="30">&nbsp;</td>
<td><input type="submit" name="button" id="button" value="确定入住"></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" background="Images/bootBg.jpg">&nbsp;</td>
</tr>
</table>

</center>
</body>
</html>

 

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

<%@ 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"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>校园宿舍管理系统</title>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="Style/Style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
</head>
<script language="JavaScript">


function mycheck(){
if(isNull(form1.Log_Date.value)){
alert("请输入选择缺寝日期!");
return false;
}
}

function isNull(str){
if ( str == "" ) return true;
var regu = "^[ ]+$";
var re = new RegExp(regu);
return re.test(str);
}


</script>
<body>
<center>
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="60" bgcolor="#E6F5FF" style="color:#06F; font-size:19px; font-weight:bolder; padding-left:50px;">校园宿舍管理系统</td>
</tr>
<tr>
<td height="30" background="Images/MenuBg.jpg">&nbsp;</td>
</tr>
<tr>
<td height="500" align="center" valign="top"><table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="191" height="500" align="center" valign="top" background="Images/leftbg.jpg">
<%@ include file="Left.jsp"%>
</td>
<td width="709" align="center" valign="top" bgcolor="#F6F9FE"><table width="709" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" background="Images/mainMenuBg.jpg" style="padding-left:25px;">学生缺寝登记</td>
</tr>
<tr>
<td height="470" align="center" valign="top" bgcolor="#F6F9FE">
<form name="form1" method="post" action="LogAddSave.action" onSubmit="return mycheck()" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" colspan="2" align="center" style="color:red;">请仔细确认信息是否正确,缺寝登记提交后将不可修改!</td>
</tr>
<tr>
<td width="33%" height="30" align="right">学号:</td>
<td width="67%"><s:property value='cnbean.Student_Username'/>
<label for="Log_StudentID"></label>
<input name="Log_StudentID" type="text" class="noshow" id="Log_StudentID" value="<s:property value='cnbean.Student_ID'/>"></td>
</tr>
<tr>
<td height="30" align="right">姓名:</td>
<td><s:property value='cnbean.Student_Name'/></td>
</tr>
<tr>
<td height="30" align="right">性别:</td>
<td><s:property value='cnbean.Student_Sex'/></td>
</tr>
<tr>
<td height="30" align="right">班级:</td>
<td><s:property value='cnbean.Student_Class'/></td>
</tr>
<tr>
<td height="30" align="right">寝室:</td>
<td><s:property value='cnbean.Domitory_Name'/></td>
</tr>
<tr>
<td height="30" align="right"><span style="color:red;">*</span>缺寝日期:</td>
<td><label for="Log_Date"></label>
<input type="text" name="Log_Date" id="Log_Date" class="Wdate" onClick="WdatePicker()"></td>
</tr>
<tr>
<td height="30" align="right">缺寝备注:</td>
<td><textarea name="Log_Remark" id="Log_Remark" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td height="30">&nbsp;</td>
<td><input type="submit" name="button" id="button" value="确认提交">
&nbsp;&nbsp;
<input type="button" name="button2" id="button2" value="返回上页" onClick="javascript:history.back(-1);"></td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" background="Images/bootBg.jpg">&nbsp;</td>
</tr>
</table>

</center>
</body>
</html>

posted on 2019-05-29 16:58  太白云生  阅读(1356)  评论(0编辑  收藏  举报