?? addroom.jsp
字號(hào):
<%@page contentType="text/html;charset=gb2312" language="java"%>
<%@page import="java.util.*"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="myconnect" scope="session" class="student.DBConnect"/>
<%
//如果助記詞還未登錄或者處于不在線狀態(tài),提示用戶先登錄系統(tǒng),并跳轉(zhuǎn)至登錄頁(yè)面
if(session.getAttribute("login")==null)
out.print("<script>alert('請(qǐng)先登錄!'); window.location.href='login.jsp' </script>");
%>
<%
String buildingid=request.getParameter("buildingid"); //取出用戶輸入的樓號(hào)
String roomid=request.getParameter("roomid"); //取出用戶輸入的房號(hào)
String sex=request.getParameter("sex"); //取出用戶輸入的性別
String amount=request.getParameter("amount"); //取出用戶輸入的入住人數(shù)
String expense=request.getParameter("expense"); //取出用戶輸入的費(fèi)用
//設(shè)置查詢條件
//如查詢條件將根據(jù)用戶輸入的樓號(hào)和房號(hào)進(jìn)行查詢,確定數(shù)據(jù)庫(kù)中是否已經(jīng)存在該條數(shù)據(jù)
if(buildingid!=null)&&(roomid!=null) {
String sqlText="select * from room where building="+buildingid+" and room="+roomid;
ResultSet rsaddroom;
//根據(jù)sqlText指定的查詢條件進(jìn)行查詢
rsaddroom=myconnect.DBQuery(sqlText);
//如果數(shù)據(jù)庫(kù)中已經(jīng)存在該條數(shù)據(jù),則錄入的數(shù)據(jù)箸重復(fù),不能進(jìn)行更新
//并顯示錯(cuò)誤信息
if(rsaddroom!=null)&&(rsaddroom.next())
request.setAttribute("message","該棟樓的該房間已經(jīng)登記!");
else {
//設(shè)置更新條件,如果用戶輸入的數(shù)據(jù)在數(shù)據(jù)庫(kù)中不存在,則要新增一條數(shù)據(jù)
String inserttext="";
//如果用戶輸入的數(shù)據(jù)庫(kù)中不存在
//則根據(jù)用戶的信息在數(shù)據(jù)庫(kù)中新增一條記錄
inserttext="insert into room values("+buildingid+","+roomid+",'"+sex+"',amount+","+expense+");";
myconnect.DBUpdate(inserttext);
request.setAttribute("message","新數(shù)據(jù)添加成功!");
}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>錄入房間信息</title>
<link href="css/mycss.css" rel="stylesheet" type="text/css">
<SCRIPT Language="JavaScript">
//下面的程序?qū)?zhí)行資料檢查
function datacheck()
{
//檢查是否輸入樓號(hào)
if(form.buildingid.value=="") {
//如果沒(méi)有輸入則顯示警告信息
alert("請(qǐng)輸入樓號(hào)!");
//將光標(biāo)移至樓號(hào)輸入欄
document.form.duildingid.focus();
}else{
//檢查是否輸入房號(hào)
if(form.roomid.value=="") {
//如果沒(méi)有輸入則顯示警告信息
alert("請(qǐng)輸入房號(hào)!");
//將光標(biāo)移至房號(hào)輸入欄
document.form.roomid.focus();
}else{
//檢查是否選擇入住性別
if(form.sex.value=="") {
//如果沒(méi)有輸入則顯示警告信息
alert("請(qǐng)選擇入住性別!");
//將光標(biāo)移至入住性別選擇欄
document.form.sex.focus();
}else{
//檢查是否輸入可住人數(shù)
if(form.amount.value=="") {
//如果沒(méi)有輸入則顯示警告信息
alert("請(qǐng)輸入可住人數(shù)!");
//將光標(biāo)移至可住人數(shù)輸入欄
document.form.amount.focus();
}else{
//檢查是否輸入住宿費(fèi)用
if(form.expense.value=="") {
//如果沒(méi)有輸入則顯示警告信息
alert("請(qǐng)輸入住宿費(fèi)用!");
//將光標(biāo)移至住宿費(fèi)用輸入欄
document.form.expense.focus();
}else{
form.submit(); //提交表單中的資料
}
}
}
}
}
}
</script>
</head>
<body bgcolor="#CFE3CA" text="#004080">
<p align="center"> </p>
<form action="addroom.jsp" method="post" name="form">
<table width="33%" border="1" align="center" bordercolor="#004080" bgcolor="#cccccc">
<tr>
<td height="47" colspan="2">
<div align="center">
<p>
<strong><font size="4">錄入房間信息</font></strong>
</p>
</div>
</td>
</tr>
<tr>
<td width="35%" height="40">
<div align="center">
樓號(hào)
</div>
</td>
<td width="70%" height="40">
<input name="studentid" type="text" size="20">
</td>
</tr>
<tr>
<td height="41">
<div align="center">
房號(hào)
</div>
</td>
<td height="41">
<input name="name" type="text" size="20">
</td>
</tr>
<tr>
<td height="34">
<div align="center">
入住性別
</div>
</td>
<td height="34">
<select name="sex">
<option value="">
請(qǐng)選擇
</option>
<option value="男">
男
</option>
<option value="女">
女
</option>
</select>
</td>
</tr>
<tr>
<td height="46">
<div align="center">
可住人數(shù)
</div>
</td>
<td height="46">
<input name="buildingid" type="text" size="20">
</td>
</tr>
<tr>
<td height="40">
<div align="center">
住宿費(fèi)用
</div>
</td>
<td height="40">
<input name="roomid" type="text" size="20">
</td>
</tr>
<tr>
<td height="40" colspan="2">
<div align="center">
<input name="Submit1" type="button" value="確定" onclick="datacheck()">
<input type="reset" name="Submit2" value="取消" >
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -