浏览房产信息:顾客登录后,可以查看所有在售房产信息;房产经纪人登录后,只能查看系统管理员授权的房产信息;系统管理员登录后可以查看全部房产信息(四种房产状态)。(3分)
顾客浏览:只需要在输出数据时加一条判断就可以筛选出在售的房产信息
if(rs.getObject(7).equals("在售"))
完整代码
User_LookHouse.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>房产信息浏览</title>
</head>
<body>
<table border="1" cellspacing="0" style="text-align:center;">
<tr>
<td align="center" width=5%>房产编号</td>
<td align="center" width=5%>户型</td>
<td align="center" width=10%>房产地址</td>
<td align="center" width=5%>建造年份</td>
<td align="center" width=5%>建造面积</td>
<td align="center" width=5%>销售报价</td>
<td align="center" width=5%>销售状态</td>
</tr>
<%
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from 房产基本信息表";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(rs.getObject(7).equals("在售"))
{
%>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
房产经纪人浏览也是得加一个判段if(AgentID.equals(rs.getObject(8)))
加上这个判断就能筛选出授权给他的,即房产基本信息表中房产经纪人ID和当前登录房产经纪人相符的一行房产信息
AgentID通过String AgentID= (String) session.getAttribute("AgentID");获取
完整代码
Agent_LookHouse.jsp
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"标签:preparedStatement,房产信息,rs,--,util,房产,信息管理系统,AgentID From: https://www.cnblogs.com/mendianyu/p/16874802.html
pageEncoding="UTF-8"%>
<%@ page import="com.Util.util" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>房产信息浏览</title>
</head>
<body>
<table border="1" cellspacing="0" style="text-align:center;">
<tr>
<td align="center" width=5%>房产编号</td>
<td align="center" width=5%>户型</td>
<td align="center" width=10%>房产地址</td>
<td align="center" width=5%>建造年份</td>
<td align="center" width=5%>建造面积</td>
<td align="center" width=5%>销售报价</td>
<td align="center" width=5%>销售状态</td>
</tr>
<%
String AgentID= (String) session.getAttribute("AgentID");
Connection connection = util.getConnection();
PreparedStatement preparedStatement=null;
ResultSet rs=null;
try {
String sql = "select * from 房产基本信息表";
preparedStatement=connection.prepareStatement(sql);
rs=preparedStatement.executeQuery();
while(rs.next()){
if(AgentID.equals(rs.getObject(8)))
{
%>
<tr>
<td align="center"><%=rs.getObject(1) %></td>
<td align="center"><%=rs.getObject(2) %></td>
<td align="center"><%=rs.getObject(3) %></td>
<td align="center"><%=rs.getObject(4) %></td>
<td align="center"><%=rs.getObject(5) %></td>
<td align="center"><%=rs.getObject(6) %></td>
<td align="center"><%=rs.getObject(7) %></td>
</tr>
<%
}
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
util.close(rs);
util.close(preparedStatement);
util.close(connection);
}
%>
</table>
<p style="text-align:center;color: black; font-family: 宋体; font-size: 20px">
<input type="button" name="back" onclick="javascript:window.history.back();" value=返回上一页>
<input type="button" value="返回菜单" onclick="location.href='menu.jsp'" /> <br>
</p>
</body>
</html>
系统管理员的浏览更简单了,不用加任何判断条件,代码这里就不写了