宿舍管理系統部分代碼實現

目錄結構:

連接數據庫功能代碼實現:

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" οnclick="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"> </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"> </td>
<td width="67%"> </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"> </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"> </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"> </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"> </td>
<td><input type="submit" name="button" id="button" value="確認提交">
  
<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"> </td>
</tr>
</table>

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章