jsp servlet javaBean后台分页实例代码解析(3)

package View; import java.io.IOException; 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 ShowViewIndex */ @WebServlet("/ShowViewIndex") public class ShowViewIndex extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public ShowViewIndex() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub request.getRequestDispatcher("/NewFile.jsp").forward(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); } }

jsp页面代码

<%@ 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>数据库内容分页显示</title> <style type="text/css"> *{ margin:0; padding:0;} ul li{ width:50px; height:24px; line-height:24px; float:left; margin-left:0px; display:inline; margin-top:5px; overflow:hidden;} ul li button{width:50px;height:24px;margin:0px;padding:0px;} </style> </head> <body> <table> <thead> <tr> <th>编号</th> <th>名称</th> <th>类型</th> <th>学号</th> <th>负责人</th> </tr> </thead> <tbody> <c:forEach var="project" items="${subResult}"> <tr> <td><c:out value="${project.projectId}"></c:out></td> <td><c:out value="${project.projectName}"></c:out></td> <td><c:out value="${project.projectType}"></c:out></td> <td><c:out value="${project.userNo}"></c:out></td> <td><c:out value="${project.projectUser}"></c:out></td> </tr> </c:forEach> </tbody> </table> <div align = "center"> <ul> <c:choose> <c:when test="${currentPageIndex>1}"> <li><a href="${pageContext.request.contextPath}/servlet/SplitPageServlet?currrentPage=${currentPageIndex-1}"><button><</button></a></li> </c:when> <c:otherwise> <li><a><button><</button></a></li> </c:otherwise> </c:choose> <% int i =(Integer)request.getAttribute("pageNumber"); for (int j=0;j<i;j++) {%> <li><a href="${pageContext.request.contextPath}/servlet/SplitPageServlet?currrentPage=<%=j+1%>"><button><%=j+1%></button></a></li> <%}%> <c:choose> <c:when test="${currentPageIndex+1<=pageNumber}"> <li><a href="${pageContext.request.contextPath}/servlet/SplitPageServlet?currrentPage=${currentPageIndex+1}"><button>></button></a></li> </c:when> <c:otherwise> <li><a><button>></button></a></li> </c:otherwise> </c:choose> </ul> </div> </body> </html>

xml代码

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzjssd.html