在今天我学会了分页查询的操作:
以下是部分代码:
index.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page import="java.util.ArrayList" %> <%@ page import="bean.policy" %><%-- Created by IntelliJ IDEA. User: Lenovo Date: 2023/4/10 Time: 15:19 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <center> <img src="LOGO.png"> </center> <% request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); Object message=request.getAttribute("message"); if(message!=null) { %> <script language="JavaScript">alert("<%=message%>")</script> <% } ArrayList<policy> policies= (ArrayList<policy>) request.getAttribute("policies"); if(policies==null){ %> <form action="Servlet?method=suoyou" method="post"> <input type="submit" value="查询"> </form> <% } else if(policies!=null){ %> <center> <form action="Servlet?method=chadata" method="post"> 政策名称:<input type="text" name="name" placeholder="请输入政策名称" style="border: none"> 发文字号:<input type="text" name="document" placeholder="请输入发文字号" style="border: none"> 发文机构:<input type="text" name="organ" placeholder="请输入发文机构" style="border: none"> 全文检索:<input type="text" name="data" style="border: none"> <input type="submit" value="搜索"> </form> <br> <br> <table border="1" cellspacing="0"> <th width="10%">id</th><th width="20%">政策名称</th><th width="20%">发文机构</th><th width="20%">颁布日期</th><th width="20%">政策分类</th><th width="10%">操作</th> <c:forEach items="${policies}" var="item"> <tr> <td>${item.id}</td> <td>${item.name}</td> <td>${item.organ}</td> <td>${item.pubdata}</td> <td>${item.type}</td> <td><a href="Servlet?method=chakan&id=${item.id}" style="text-decoration: none">查看</a> </td> </tr> </c:forEach> </table> <br> 共${sum}条记录,当前第${cpage}/${tpage}页 <% String dd= request.getAttribute("dd").toString(); if(Integer.parseInt(request.getAttribute("sum").toString())<10){ } else if(dd.equals("d")){%> <a href="Servlet?method=suoyou&cp=1">首页</a> <a href="Servlet?method=suoyou&cp=${cpage-1<=0?1:cpage-1}">上一页</a> <a href="Servlet?method=suoyou&cp=${cpage+1>=tpage?tpage:cpage+1}">下一页</a> <a href="Servlet?method=suoyou&cp=${tpage}">尾页</a> <% } else if(dd.equals("dd")){%> <a href="Servlet?method=chadata&cp=1&name=<%=request.getAttribute("name")%>&document=<%=request.getAttribute("document")%>&organ=<%=request.getAttribute("organ")%>">首页</a> <a href="Servlet?method=chadata&cp=${cpage-1<=0?1:cpage-1}&name=<%=request.getAttribute("name")%>&document=<%=request.getAttribute("document")%>&organ=<%=request.getAttribute("organ")%>">上一页</a> <a href="Servlet?method=chadata&cp=${cpage+1>=tpage?tpage:cpage+1}&name=<%=request.getAttribute("name")%>&document=<%=request.getAttribute("document")%>&organ=<%=request.getAttribute("organ")%>">下一页</a> <a href="Servlet?method=chadata&cp=${tpage}&name=<%=request.getAttribute("name")%>&document=<%=request.getAttribute("document")%>&organ=<%=request.getAttribute("organ")%>">尾页</a> <% } %> </center> <% } %> </body> </html>
标签:organ,cpage,学习,item,内容,policies,tpage,document From: https://www.cnblogs.com/nanbei666/p/17304649.html