考试售房系统

12.20

我把考试题重新修改完善了一下,当然由于web技术太菜,还是没能实现全部功能,往后会一点一点改这个代码的,直到特别完美的实现这个售房系统。

下面是代码部分。

登录界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录界面</title>
</head>
<script>
var error='<%=request.getParameter("error")%>';
if(error=='yes'){
alert('账号或密码错误!');
}
</script>
<body>
<form>
<table align="center" border="1">
<tr>
<td>账号:</td>
<td>
<input type="text" name="num">
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input type="text" name="password">
</td>
</tr>
<tr align="center">
<td colspan="2">
<input type="submit" value="登录" formaction="lei.jsp" method="post">
</td>
<td colspan="2">
<input type="submit" value="注册" formaction="zhuce.jsp" method="post">
</td>
</tr>
</table>
</form>
</body>
</html>

注册界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>增加顾客对象页面</title>
</head>
<body>
<script>
var addstus='<%=request.getParameter("addgu")%>';
if(addstus=="yes"){
alert("添加成功!");
}
</script>
<form action="servlet?method=addgu" method="post">
<table align="center">
<tr>
<td>身份证号:</td>
<td>
<input type="text" name="IdNumber">
</td>
</tr>
<tr>
<td>姓名:</td>
<td>
<input type="text" name="UserName">
</td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="text" name="Sex">
</td>
</tr>
<tr>
<td>手机号码:</td>
<td>
<input type="text" name="Phone">
</td>
</tr>
<tr>
<td>家庭住址:</td>
<td>
<input type="text" name="User">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="确定">
<input type="submit" value="返回" formaction="gongneng.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

三个查询和浏览界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>显示页面</title>
</head>
<body>
<form>
<table>
<tr>
<td>房产编号</td>
<td>户型</td>
<td>房产地址</td>
<td>建造年份</td>
<td>建造面积</td>
<td>销售报价</td>
<td>销售状态</td>

</tr>
<tr>
<c:forEach items="${list}" var="item">
<tr>
<td>${item.houseID}</td>
<td>${item.roomType}</td>
<td>${item.address}</td>
<td>${item.year}</td>
<td>${item.area}</td>
<td>${item.sales}</td>
<td>${item.status}</td>

</tr>
</c:forEach>
</tr>
<tr>
<td>
<input type="submit" value="返回" formaction="lei.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>显示页面</title>
</head>
<body>
<form>
<table>
<tr>
<td>顾客ID</td>
<td>姓名</td>
<td>性别</td>
<td>身份证号</td>
<td>手机</td>

<td>家庭住址</td>

</tr>
<tr>
<c:forEach items="${list}" var="item">
<tr>
<td>${item.userID}</td>
<td>${item.userName}</td>
<td>${item.sex}</td>
<td>${item.idNumber}</td>
<td>${item.phone}</td>
<td>${item.user}</td>
</tr>
</c:forEach>
</tr>
<tr>
<td>
<input type="submit" value="返回" formaction="lei.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>显示页面</title>
</head>
<body>
<form>
<table>
<tr>
<td>工号</td>
<td>姓名</td>
<td>家庭住址</td>
<td>手机</td>
</tr>
<tr>
<c:forEach items="${list}" var="item">
<tr>
<td>${item.agentID}</td>
<td>${item.agentName}</td>
<td>${item.agentAddress}</td>
<td>${item.phone}</td>
</tr>
</c:forEach>
</tr>
<tr>
<td>
<input type="submit" value="返回" formaction="lei.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

房产功能选择界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>功能选择界面</title>
</head>
<body>
<form>
<table align="center" border="1">
<tr align="center">
<td>
<input type="submit" value="查看个人信息" formaction="servlet?method=show" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="修改个人密码" formaction="gai.jsp " formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="浏览房产信息" formaction="servlet?method=dengji" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="查询房产" formaction="cha.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="房产交易" formaction="jiao.jsp" formmethod="post">
</td>
</tr>


<tr align="center">
<td>
<input type="submit" value="返回" formaction="lei.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

修改界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Object message=request.getAttribute("message");
if(!(message==null||message.equals("")))
{
%>
<script type="text/javascript">alert('<%=message%>')</script>
<%
request.setAttribute("message", null);
}
%>
</body>
</html>

 

管理员功能界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>功能选择界面</title>
</head>
<body>
<form>
<table align="center" border="1">
<tr align="center">
<td>
<input type="submit" value="新添房产信息" formaction="house.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="房产授权" formaction="gai.jsp " formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="停售房产" formaction="servlet?method=dengji" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="查询房产信息" formaction="servlet?method=cha" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="顾客审核" formaction="numselect.jsp" formmethod="post">
</td>
</tr>

<tr align="center">
<td>
<input type="submit" value="新增房产经纪人" formaction="ren.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="密码重置" formaction="numselect.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="返回" formaction="login.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

顾客功能界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>功能选择界面</title>
</head>
<body>
<form>
<table align="center" border="1">
<tr align="center">
<td>
<input type="submit" value="查看个人信息" formaction="servlet?method=chag.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="修改个人密码" formaction="gai.jsp " formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="浏览房产信息" formaction="servlet?method=cha" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="查询房产" formaction="servlet?method=cha" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="购买房产" formaction="numselect.jsp" formmethod="post">
</td>
</tr>


<tr align="center">
<td>
<input type="submit" value="返回" formaction="login.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

经纪人功能界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>功能选择界面</title>
</head>
<body>
<form>
<table align="center" border="1">
<tr align="center">
<td>
<input type="submit" value="查看个人信息" formaction="servlet?method=show" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="修改个人密码" formaction="gai.jsp " formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="浏览房产信息" formaction="servlet?method=dengji" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="查询房产" formaction="cha.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="房产交易" formaction="jiao.jsp" formmethod="post">
</td>
</tr>


<tr align="center">
<td>
<input type="submit" value="返回" formaction="lei.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

浏览房产界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>增加顾客对象页面</title>
</head>
<body>
<script>
var addstus='<%=request.getParameter("addgu")%>';
if(addstus=="yes"){
alert("添加成功!");
}
</script>
<form action="servlet?method=addfang" method="post">
<table align="center">
<tr>
<td>房产编号:</td>
<td>
<input type="text" name="HouseID">
</td>
</tr>
<tr>
<td>户型</td>
<td>
<input type="text" name="RoomType" list="elist">
<datalist id="elist">
<option>四室两厅</option>
<option>四室一厅</option>
<option>三室两厅</option>
<option>三室一厅</option>
<option>两室两厅</option>
<option>两室一厅</option>
</datalist>
</td>
</tr>
<tr>
<td>房产地址:</td>
<td>
<input type="text" name="Address">
</td>
</tr>
<tr>
<td>建造年份:</td>
<td>
<input type="text" name="Year">
</td>
</tr>
<tr>
<td>建造面积:</td>
<td>
<input type="text" name="Area">
</td>
</tr>
<tr>
<td>销售报价:</td>
<td>
<input type="text" name="Sales">
</td>
</tr>
<tr>
<td>销售状态</td>
<td>
<input type="text" name="Status" list="elist">
<datalist id="elist">
<option>在售</option>
<option>待售</option>
<option>意向</option>
<option>售出</option>
<option>停售</option>
</datalist>
</td>
</tr>
<tr>
<td>销售报价:</td>
<td>
<input type="text" name="Sales">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="确定">
<input type="submit" value="返回" formaction="guanli.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

分类登录界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>功能选择界面</title>
</head>
<body>
<form>
<table align="center" border="1">
<tr align="center">
<td>
<input type="submit" value="顾客" formaction="gongneng.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="房产经纪" formaction="fangchan.jsp " formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="系统管理员" formaction="guanli.jsp" formmethod="post">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" value="返回" formaction="login.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

 

添加经纪人界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>增加顾客对象页面</title>
</head>
<body>
<script>
var addstus='<%=request.getParameter("addgu")%>';
if(addstus=="yes"){
alert("添加成功!");
}
</script>
<form action="servlet?method=addren" method="post">
<table align="center">
<tr>
<td>工号:</td>
<td>
<input type="text" name="AgentID">
</td>
</tr>
<tr>
<td>姓名:</td>
<td>
<input type="text" name="AgentName">
</td>
</tr>
<tr>
<td>家庭住址:</td>
<td>
<input type="text" name="AgentAddress">
</td>
</tr>
<tr>
<td>手机:</td>
<td>
<input type="text" name="Phone">
</td>
</tr>

<tr align="center">
<td>
<input type="submit" value="确定">
<input type="submit" value="返回" formaction="lei.jsp" formmethod="post">
</td>
</tr>
</table>
</form>
</body>
</html>

servlet层:

package com.pp;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class servlet
*/
@WebServlet("/servlet")
public class servlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public servlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
private void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String teacher=request.getParameter("num");
if("123".equals(teacher)) {

request.getRequestDispatcher("lei.jsp").forward(request, response);
}
else {
response.sendRedirect("login.jsp?error=yes");
}
}
private void addgu(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String UserName=request.getParameter("UserName");
String Sex=request.getParameter("Sex");
String IdNumber=request.getParameter("IdNumber");
String Phone=request.getParameter("Phone");
String User=request.getParameter("User");

guke stu=new guke(UserName,Sex,IdNumber,Phone,User);
dao L=new dao();
L.insert(stu);
response.sendRedirect("zhuce.jsp?addgu=yes");
}
private void addren(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String AgentID=request.getParameter("AgentID");
String AgentName=request.getParameter("AgentName");
String AgentAddress=request.getParameter("AgentAddress");
String Phone=request.getParameter("Phone");

ren stu=new ren(AgentID,AgentName,AgentAddress,Phone);
dao L=new dao();
L.insertr(stu);
response.sendRedirect("zhuce.jsp?addgu=yes");
}
private void addfang(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String HouseID=request.getParameter("HouseID");
String RoomType=request.getParameter("RoomType");
String Address=request.getParameter("Address");
String Year=request.getParameter("Year");
String Area=request.getParameter("Area");
String Sales=request.getParameter("Sales");
String Status=request.getParameter("Status");
fang stu=new fang(HouseID,RoomType,Address,Year,Area,Sales,Status);
dao L=new dao();
L.insertf(stu);
response.sendRedirect("lei.jsp?addgu=yes");
}
private void show(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
dao L=new dao();
List<ren> list=L.select();
request.setAttribute("list",list);
request.getRequestDispatcher("chajing.jsp").forward(request, response);
}
private void cha(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
dao L=new dao();
List<fang> list=L.select1();
request.setAttribute("list",list);
request.getRequestDispatcher("cha.jsp").forward(request, response);
}
private void chag(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
dao L=new dao();
List<guke> list=L.select2();
request.setAttribute("list",list);
request.getRequestDispatcher("chag.jsp").forward(request, response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
String method=request.getParameter("method");
if("login".equals(method)) {
login(request,response);
}
else if("addgu".equals(method)) {
addgu(request,response);
}
else if("addfang".equals(method)) {
addfang(request,response);
}
else if("addren".equals(method)) {
addren(request,response);
}
else if("show".equals(method)) {
show(request,response);
}
else if("cha".equals(method)) {
cha(request,response);
}
else if("chag".equals(method)) {
chag(request,response);
}
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

}

链接数据库:

package com.pp;
import java.sql.*;
public class DBUtil{
private DBUtil() {}
static {
try {
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection("jdbc:mysql://localhost:3306/shujuku?serverTimezone=UTC&useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8","root","123456");
}
public static void close(Connection conn,Statement ps,ResultSet rs) {
if(rs!=null) {
try {
rs.close();
}catch(SQLException s) {
s.printStackTrace();
}
}
if(ps!=null) {
try {
ps.close();
}catch(SQLException s) {
s.printStackTrace();
}
}
if(conn!=null) {
try {
conn.close();
}catch(SQLException s) {
s.printStackTrace();
}
}
}
}

密码层:

package com.pp;

public class password {
private String num;
private String password;
private String id;
public password(String num, String password, String id) {
super();
this.num = num;
this.password = password;
this.id = id;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

其它主类:

package com.pp;

public class fang {
private String HouseID;
private String RoomType;
private String Address;
private String Year;
private String Area;
private String Sales;
private String Status;
public String getHouseID() {
return HouseID;
}
public void setHouseID(String houseID) {
HouseID = houseID;
}
public String getRoomType() {
return RoomType;
}
public void setRoomType(String roomType) {
RoomType = roomType;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public String getYear() {
return Year;
}
public void setYear(String year) {
Year = year;
}
public String getArea() {
return Area;
}
public void setArea(String area) {
Area = area;
}
public String getSales() {
return Sales;
}
public void setSales(String sales) {
Sales = sales;
}
public String getStatus() {
return Status;
}
public void setStatus(String status) {
Status = status;
}
public fang(String a,String b,String c,String d,String e,String f,String g) {
super();
this.HouseID=a;
this.RoomType=b;
this.Address=c;
this.Year=d;
this.Area=e;
this.Sales=f;
this.Status=g;
}
}

 

package com.pp;

public class ren {
private String AgentID;
private String AgentName;
private String AgentAddress;
private String Phone;
public String getAgentID() {
return AgentID;
}
public void setAgentID(String agentID) {
AgentID = agentID;
}
public String getAgentName() {
return AgentName;
}
public void setAgentName(String agentName) {
AgentName = agentName;
}
public String getAgentAddress() {
return AgentAddress;
}
public void setAgentAddress(String agentAddress) {
AgentAddress = agentAddress;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public ren(String a,String b,String c,String d) {
super();
this.AgentAddress=c;
this.AgentID=a;
this.AgentName=b;
this.Phone=d;
}
}

 

package com.pp;

public class guke {
private String UserName;
private String Sex;
private String IdNumber;
private String Phone;
private String User;
public String getUserName() {
return UserName;
}
public void setUserName(String userName) {
UserName = userName;
}
public String getSex() {
return Sex;
}
public void setSex(String sex) {
Sex = sex;
}
public String getIdNumber() {
return IdNumber;
}
public void setIdNumber(String idNumber) {
IdNumber = idNumber;
}
public String getPhone() {
return Phone;
}
public void setPhone(String phone) {
Phone = phone;
}
public String getUser() {
return User;
}
public void setUser(String user) {
User = user;
}
public guke(String a,String b,String c,String d,String e) {
super();
this.IdNumber=c;
this.Phone=d;
this.Sex=b;
this.User=e;
this.UserName=a;
}
}

 

posted @ 2020-12-20 11:15  潘福龙  阅读(74)  评论(0编辑  收藏  举报