diff --git "a/08 \350\224\241\346\263\275\351\222\246/20230609 \346\210\277\345\261\213\347\263\273\347\273\237.md" "b/08 \350\224\241\346\263\275\351\222\246/20230609 \346\210\277\345\261\213\347\263\273\347\273\237.md" new file mode 100644 index 0000000000000000000000000000000000000000..6065fc83e07263fb8ea8baba9590d0a188ac2ff9 --- /dev/null +++ "b/08 \350\224\241\346\263\275\351\222\246/20230609 \346\210\277\345\261\213\347\263\273\347\273\237.md" @@ -0,0 +1,102 @@ +ListServlet +~~~java +package servlet; + +import bean.HouseInfo; +import utils.DBUtil; + +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("/list") +public class ListServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + request.setCharacterEncoding("utf-8"); + response.setContentType("text/html;charset=utf-8"); + String sql = "select * from house_info i,house_type t where i.house_type_id=t.id"; + try { + ResultSet rs = DBUtil.qurey(sql); + ArrayList list = new ArrayList(); + while (rs.next()) { + int id = rs.getInt("i.id"); + String mode = rs.getString("lease_mode"); + double rent = rs.getDouble("rent"); + String contacts = rs.getString("contacts"); + String method = rs.getString("deposit_method"); + int typeId = rs.getInt("house_type_id"); + String address = rs.getString("address"); + String type = rs.getString("type"); + HouseInfo info = new HouseInfo(id, mode, rent, contacts, method, typeId, address, type); + list.add(info); + //将集合添加request到请求域中 + request.setAttribute("list",list); + //请求转发到list.jsp + 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 { + + } +} + +~~~ + +jsp + +~~~jsp +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%-- + Created by IntelliJ IDEA. + User: Administrator + Date: 2023-06-07 + Time: 11:07 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + 房屋系统 + + + + + + + + + + + + + + + + + + + + + + + + + +
编号租凭方式租金联系人押金方式房屋类型详细地址
${h.id}${h.mode}${h.rent}${h.contacts}${h.method}${h.type}${h.address}
+ + + +~~~ +