?? query_house.jsp
字號(hào):
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<% import="java.util.*" %>
<% import="java.sql.*" %>
<jsp:useBean id="myconnect" scope="session" class="student.DBConnect"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
//如果用戶還未登錄或者處于在線狀態(tài),提示用戶先登錄系統(tǒng),并跳轉(zhuǎn)至登錄頁面
if(session.getAttribute("login")==null)
out.print("<script>alert('請(qǐng)先登錄!'); window.location.href='login.jsp' </script>");
%>
<%
String buildingid=request.getParameter("builkdigid"); //取出用戶輸入的樓號(hào)
String houseid=request.getParameter("houseid"); //取出用戶輸入的房號(hào)
String sqlText="";
//對(duì)查詢條件的處理
//如果用戶查詢指定樓的信息即樓號(hào)不為空,見分曉在查詢條件中進(jìn)行設(shè)置
if((buildingid!=null) && (!buildingid.equals(""))) {
sqlText+="and room="+houseid;
}
} else {
//如果相應(yīng)的樓號(hào)為空而房號(hào)信息不為空,則在查詢條件中只設(shè)置固定房號(hào)的查詢條件
if((houseid!=null) && (!houseid.equals(""))) {
sqlText="room="+houseid;
}
}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>查詢房間</title>
<link href="css/mycss.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#CFE3CA" text="#004080">
<p>
</p>
<form name="form1" method="post" action="query_house.jsp">
<table width="33%" border="1" align="center" bordercolor="#004080" bgcolor="#cccccc">
<tr>
<td colspan="2" height="56">
<div align="center">
<strong><font size="5">房間信息查詢</font></strong>
</div>
</td>
</tr>
<tr>
<td width="35%" height="30">
<div align="center">
樓號(hào)
</div>
</td>
<td width="65%">
<input name="buildingid" type="text" size="20">
</td>
</tr>
<tr>
<td height="34">
<div align="center">
房號(hào)
</div>
</td>
<td>
<input name="houseid" type="text" size="20">
</td>
</tr>
<tr>
<td height="47" colspan="2">
<div align="center">
<input type="submit" name="Submit" value="查 詢">
</div>
</td>
</tr>
</table>
</form>
<%
//根據(jù)指定條件進(jìn)行查詢
ResultSet rsroom;
//如果sqlText 不為空說明用戶希望查找指定條件的房間信息
if((sqlText!=null) && (!sqlText.equals(""))) {
sqlText="select *from room where"+sqlText;"
}
//如sqlText為空說明用戶希望查找所有房間信息
else {
sqlText="select * from room";
}
rsroom=myconnect.DBQuery(sqlText);
%>
<table width="85%" border="1" height="60" align="center" bordercolor="#004080" bgcolor="#cccccc">
<tr>
<td width="15%" height="30">
<div align="center">
樓號(hào)
</div>
</td>
<td width="15%">
<div align="center">
房號(hào)
</div>
</td>
<td width="25%">
<div align="center">
入住性別
</div>
</td>
<td width="25%">
<div align="center">
可入住人數(shù)
</div>
</td>
<td width="20%">
<div align="center">
費(fèi)用
</div>
</td>
<%
while(rsroom!=null && rsroom.next()) { //這里有一個(gè)陌生的"{",哈哈,我知道了,對(duì)應(yīng)最后的那個(gè)"<% } %>"
%>
<tr>
<td height="30">
<div align="center">
<%
String buildings=new String(rsroom.getString("building").getBytes("8859_1"),"gb2312");
%>
<%=buildings %>
</div>
</td>
<td>
<div align="center">
<%
String houses=new String(rsroom.getString("room").getBytes("8859_1"),"gb2312");
%>
<%=houses %>
</div>
</td>
<td>
<div align="center">
<%
String sexs=new String(rsroom.getString("sex").getBytes("8859_1"),"gb2312");
%>
<%=sexs %>
</div>
</td>
<td>
<div align="center">
<%=rsroom.getInt("amount") %>
</div>
</td>
<td>
<div align="center">
<%=rsroom.getFloat("expense") %>
</div>
</td>
</tr>
<%
}
%>
</table>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -