diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/gongju/DBUtil.java" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/gongju/DBUtil.java" new file mode 100644 index 0000000000000000000000000000000000000000..52baf903c19485e3d009091553b14dd9bad4e865 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/gongju/DBUtil.java" @@ -0,0 +1,51 @@ +package gongju; + +import java.sql.*; + +public class DBUtil { + static String url="jdbc:mysql:///test?characterEncoding=utf8"; + static String user = "root"; + static String password = "root"; + static { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } +public static Connection getconn() throws SQLException { + Connection conn = DriverManager.getConnection(url,user,password); + return conn; +} +public static ResultSet query(String sql , Object...tj) throws SQLException { + Connection conn = getconn(); + PreparedStatement pre = conn.prepareStatement(sql); + ResultSet re = null; + for (int i = 0; i < tj.length; i++) { + pre.setObject((i+1),tj[i]); + } + re = pre.executeQuery(); + return re; +} + public static int update(String sql , Object...tj) throws SQLException { + Connection conn = getconn(); + PreparedStatement pre = conn.prepareStatement(sql); + int re = 0; + for (int i = 0; i < tj.length; i++) { + pre.setObject((i+1),tj[i]); + } + re = pre.executeUpdate(); + return re; + } + public static void close(ResultSet re , PreparedStatement pre , Connection conn) throws SQLException { + if (re!=null){ + re.close(); + } + if (pre!=null){ + pre.close(); + } + if (conn!=null){ + conn.close(); + } + } +} diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/pickaging/HouseInfo.java" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/pickaging/HouseInfo.java" new file mode 100644 index 0000000000000000000000000000000000000000..c7918dab9eb699b2434bf6f3840fc7dae8111635 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/pickaging/HouseInfo.java" @@ -0,0 +1,93 @@ +package pickaging; + +public class HouseInfo { + private int id; + private String mode; + private double rent; + private String cont; + private String method; + private int house; + private String addr; + + public HouseInfo() { + } + + public HouseInfo(int id, String mode, double rent, String cont, String method, int house, String addr) { + this.id = id; + this.mode = mode; + this.rent = rent; + this.cont = cont; + this.method = method; + this.house = house; + this.addr = addr; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getMode() { + return mode; + } + + public void setMode(String mode) { + this.mode = mode; + } + + public double getRent() { + return rent; + } + + public void setRent(double rent) { + this.rent = rent; + } + + public String getCont() { + return cont; + } + + public void setCont(String cont) { + this.cont = cont; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public int getHouse() { + return house; + } + + public void setHouse(int house) { + this.house = house; + } + + public String getAddr() { + return addr; + } + + public void setAddr(String addr) { + this.addr = addr; + } + + @Override + public String toString() { + return "HouseInfo{" + + "id=" + id + + ", mode='" + mode + '\'' + + ", rent=" + rent + + ", cont='" + cont + '\'' + + ", method='" + method + '\'' + + ", house=" + house + + ", addr='" + addr + '\'' + + '}'; + } +} diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/pickaging/HouseType.java" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/pickaging/HouseType.java" new file mode 100644 index 0000000000000000000000000000000000000000..ecf1d54f26bd5d33ac18e2a662fc5393fb84b836 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/pickaging/HouseType.java" @@ -0,0 +1,38 @@ +package pickaging; + +public class HouseType { + private int id; + private String type; + + public HouseType() { + } + + public HouseType(int id, String type) { + this.id = id; + this.type = type; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "HouseType{" + + "id=" + id + + ", type='" + type + '\'' + + '}'; + } +} diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Add.java" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Add.java" new file mode 100644 index 0000000000000000000000000000000000000000..418b7aeb14fa3684f4dc1e76429a88d8b8a4aed5 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Add.java" @@ -0,0 +1,44 @@ +package yingyong; + +import gongju.DBUtil; +import pickaging.HouseInfo; +import pickaging.HouseType; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +@WebServlet("/add") +public class Add extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf8"); + response.setContentType("text/html;charset=utf8"); + String sql = "select * from house_type;"; + try { + ResultSet re = DBUtil.query(sql); + ArrayList list = new ArrayList<>(); + while (re.next()){ + int id = re.getInt("id"); + String type = re.getString("type"); + HouseType ht = new HouseType(id, type); + list.add(ht); + } + request.setAttribute("list",list); + request.getRequestDispatcher("WEB-INF/add.jsp").forward(request,response); + } catch (SQLException e) { + e.printStackTrace(); + } + + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Insert.java" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Insert.java" new file mode 100644 index 0000000000000000000000000000000000000000..c20b1135431afac173b816f3976774b948fed91c --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Insert.java" @@ -0,0 +1,43 @@ +package yingyong; + +import gongju.DBUtil; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.SQLException; + +@WebServlet("/insert") +public class Insert extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doPost(request,response); + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf8"); + response.setContentType("text/html;charset=utf8"); + String id = request.getParameter("id"); + String mode = request.getParameter("mode"); + String rent = request.getParameter("rent"); + String cont = request.getParameter("cont"); + String method = request.getParameter("method"); + int house = Integer.parseInt(request.getParameter("type")); + String addr = request.getParameter("addr"); + String sql = "insert into house_info values (0,?,?,?,?,?,?)"; + int i = 0; + try { + i = DBUtil.update(sql,mode, rent, cont, method, house, addr); + } catch (SQLException e) { + throw new RuntimeException(e); + } + if (i>0){ + response.getWriter().write(""); +// resp.getWriter().write(""); + }else { + response.getWriter().write("添加失败"); + } + } +} diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Select.java" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Select.java" new file mode 100644 index 0000000000000000000000000000000000000000..cba8b34468214fd65279ad210b3304a93429d789 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/src/yingyong/Select.java" @@ -0,0 +1,48 @@ +package yingyong; + +import gongju.DBUtil; +import pickaging.HouseInfo; + +import javax.servlet.*; +import javax.servlet.http.*; +import javax.servlet.annotation.*; +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; + +@WebServlet("/select") +public class Select extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf8"); + response.setContentType("text/html;charset=utf8"); + String sql = "select * from house_info i left join house_type t on i.house_type_id = t.id"; + try { + ResultSet re = DBUtil.query(sql); + ArrayList list = new ArrayList<>(); + while (re.next()){ + int id = re.getInt(1); + int typeid = re.getInt(6); + String mode = re.getString(2); + double rent = re.getDouble(3); + String cont = re.getString(4); + String depo = re.getString(5); + String addr = re.getString(7); + int tid = re.getInt(8); + String type = re.getString(9); + HouseInfo hi = new HouseInfo(id, mode, rent, cont, depo, tid, addr); + list.add(hi); + } + request.setAttribute("list",list); + request.getRequestDispatcher("WEB-INF/list.jsp").forward(request,response); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } +} diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/add.jsp" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/add.jsp" new file mode 100644 index 0000000000000000000000000000000000000000..9642a2955bbdb447a19e5680db7f4975e1b7ac2e --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/add.jsp" @@ -0,0 +1,60 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 11:22 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
租赁方式
租金
联系人
押金方式
房屋类型 + +
详细地址
+
+ + diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/jstl.jar" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/jstl.jar" new file mode 100644 index 0000000000000000000000000000000000000000..a02abecc8b888f09e4d1f9e4c9790dc482426d4f Binary files /dev/null and "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/jstl.jar" differ diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/mysql-connector-java-5.1.48.jar" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/mysql-connector-java-5.1.48.jar" new file mode 100644 index 0000000000000000000000000000000000000000..bd1c4bbc218ccff3c5a0dc9a09d248c54c577fd8 Binary files /dev/null and "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/mysql-connector-java-5.1.48.jar" differ diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/servlet-api.jar" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/servlet-api.jar" new file mode 100644 index 0000000000000000000000000000000000000000..daf690af39e115e15974b23843a3987eb3089e18 Binary files /dev/null and "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/servlet-api.jar" differ diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/standard.jar" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/standard.jar" new file mode 100644 index 0000000000000000000000000000000000000000..bc528acb949096eeb2e3048de1ff5b9ab12a66c5 Binary files /dev/null and "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/lib/standard.jar" differ diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/list.jsp" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/list.jsp" new file mode 100644 index 0000000000000000000000000000000000000000..f7b55e8c08af57b7e52a96d41a1f14848a83bc45 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/list.jsp" @@ -0,0 +1,40 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 10:59 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
编号租赁方式租金(元)联系人押金方式房屋类型详细地址
${fz.id}${fz.mode}${fz.rent}${fz.cont}${fz.method}${fz.house}${fz.addr}
+ + diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/web.xml" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/web.xml" new file mode 100644 index 0000000000000000000000000000000000000000..d80081d1318531b6c30eaf0d748bf80a0b2e042a --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/WEB-INF/web.xml" @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git "a/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/index.jsp" "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/index.jsp" new file mode 100644 index 0000000000000000000000000000000000000000..b32a70371c315736eed2e833cbbc056086e901d9 --- /dev/null +++ "b/21 \345\210\230\345\260\221\346\265\267/2023 0607 \346\210\277\345\255\220/web/index.jsp" @@ -0,0 +1,16 @@ +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 08:48 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + $Title$ + + + $END$ + +