zoukankan      html  css  js  c++  java
  • httpservlet里单纯分页

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // TODO Auto-generated method stub
                 //对List数据分页
                 req.setAttribute("list", list);
         int pageNos;
         if (req.getParameter("pageNos") == null
                 || Integer.parseInt(req.getParameter("pageNos")) < 1) {
             pageNos = 1;
         } else {
             pageNos = Integer.parseInt(req.getParameter("pageNos"));
         }
         req.setAttribute("pageNos", pageNos);
         int size=list.size();
         int countPage = size%4==0? size/4:size/4+1;
         // 总页数
         req.setAttribute("countPage", countPage);
         req.getRequestDispatcher("search.jsp").forward(req, resp);
    }
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
      <base href="<%=basePath%>">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>结果</title>
     <link href="css/style.css" rel="stylesheet">
    </head>
    <body>
        <%    
            
            String 查找的参数 = request.getParameter("查找的参数");
        %>
    
        
    <form action="search" method="get" enctype="application/x-www-form-urlencoded">
    <img src="image/logo.jpg" height="40px"/>
    <input id="css1" name="查找的参数" value=<%=查找的参数%> maxlength="30">
    <span ><input type="submit" id="css2" value="搜索一下"></span>
    
       <c:forEach var="li" items="${list}" begin="${(pageNos-1)*4 }" end="${pageNos*4-1}">
      <br>
       <p>数据  </p>
    
       <br/>
       </c:forEach>
    
       <center>
       <c:if test="${pageNos>1 }">
    <a href="search?查找的参数=<%=查找的参数%>&pageNos=1" >首页</a>
    <a href="search?查找的参数=<%=查找的参数%>&pageNos=${pageNos-1 }">上一页</a>
    </c:if>
    <c:if test="${pageNos <countPage }">
    <a href="search?查找的参数=<%=查找的参数%>&pageNos=${pageNos+1 }">下一页</a>
    <a href="search?查找的参数=<%=查找的参数%>&pageNos=${countPage }">末页</a>
    </c:if>
    </center>
    
    <h4 align="center">共${countPage}页  
    <input type="text" value="${pageNos}" name="pageNos" size="1"><input type="submit" value="go">
    
    </h4>
    </form>
  • 相关阅读:
    python爬虫学习
    Java基础知识11--Optional类
    07 Windows访问远程共享文件夹---利用\IP地址
    Springcloud 学习笔记15-打开postman console控制台,查看接口测试打印log日志信息
    Springcloud 学习笔记14-IaaS, PaaS和SaaS的区别
    Springcloud 学习笔记13-使用PostMan上传/下载文件,前后端联合测试
    Java基础知识10--Stream API详解02
    Java基础知识09--Stream API详解01
    洛谷 P2587 [ZJOI2008]泡泡堂(贪心)
    洛谷 P3199 [HNOI2009]最小圈(01分数规划,spfa判负环)
  • 原文地址:https://www.cnblogs.com/tk55/p/8951507.html
Copyright © 2011-2022 走看看