当前位置:网站首页>JSP - paging
JSP - paging
2022-07-01 06:57:00 【allway2】
Introduce
JavaServer Pages or JSP It's based on Java Technology , For creating dynamic web pages .JSP Use special JSP Tag help in HTML File insert Java Code . for example , Displays the first five even numbers JSP The page will look like this ,
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <style> body{ padding: 50px; } </style> <body> <% for(int i=0;i<10;i++){ if(i%2==0) out.print("<h1>Even No: "+i+"</h1>"); } %> </body> </html>
Pagination
Suppose there are multiple records in our database . under these circumstances , We use paging to break down records into more readable bits , This is true for both users and processors , Because a single page with multiple records may take time to load and users may be tired . Let's look at an example of paging ,
We will be in Netbeans Create our project in , Use XAMPP The server is connected to our SQL database . The following is the project structure .

index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <a href="view.jsp?page=1">View Employees</a> </body> </html>
view.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <style> body{ padding: 50px; } </style> <body> <%@ page import="java.util.*,Emp.*,EmpDao.*" %> <% String spageid=request.getParameter("page"); int pageid=Integer.parseInt(spageid); int total=5; if(pageid!=1){ pageid=pageid-1; pageid=pageid*total+1; } List<Emp> list=EmpDao.getRecords(pageid,total); out.print("<h1>Page No: "+spageid+"</h1>"); out.print("<table border='1' cellpadding='4' width='60%'>"); out.print("<tr><th>Id</th><th>Name</th><th>Salary</th>"); for(Emp e:list){ out.print("<tr><td>"+e.getId()+"</td><td>"+e.getName()+"</td><td>"+e.getSalary()+"</td></tr>"); } out.print("</table>"); %> <a href="view.jsp?page=1">1</a> <a href="view.jsp?page=2">2</a> <a href="view.jsp?page=3">3</a> </body> </html>
Emp.java
package Emp; /** * * @author 91963 */ public class Emp { private int id; private String name; private float salary; public void setId(int aInt) { id = aInt; } public void setName(String string) { name = string; } public void setSalary(float aFloat) { salary = aFloat; } public int getId(){ return id; } public String getName(){ return name; } public float getSalary(){ return salary; } }
EmpDao.java
package EmpDao; import java.sql.*; import Emp.*; import java.util.ArrayList; import java.util.List; /** * * @author 91963 */ public class EmpDao { public static Connection getConnection(){ Connection con=null; try{ Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root",""); }catch(ClassNotFoundException | SQLException e){System.out.println(e);} return con; } public static List<Emp> getRecords(int start,int total){ List<Emp> list=new ArrayList<>(); try { try (Connection con = getConnection()) { PreparedStatement ps=con.prepareStatement("select * from emp limit "+(start-1)+","+total); ResultSet rs=ps.executeQuery(); while(rs.next()){ Emp e=new Emp(); e.setId(rs.getInt(1)); e.setName(rs.getString(2)); e.setSalary(rs.getFloat(3)); list.add(e); } } }catch(Exception e){System.out.println(e);} return list; } }
Output




common problem
- What is? JSP?
JavaServer Pages or JSP It's based on Java Technology , For creating dynamic web pages .JSP Use the only JSP Tag help in HTML File insert Java Code .
- What is pagination ?
Paging is used to divide records into more convenient readable bits , This is true for both users and processors , Because a single page with multiple records may take time to load and users may be tired .
Key points
This blog covers JavaServer Pages All the necessary points for paging in , The function and the method of paging application are discussed in detail . And it's in JavaServer Pages In the implementation of .
边栏推荐
- 女生适合学产品经理吗?有什么优势?
- Insufficient free space after clearing expired cache entries - consider increasing the maximum cache space
- 为什么这么多人转行产品经理?产品经理发展前景如何?
- The code generator has eliminated the styling of xxxx js as it exceeds the max of 500kb
- 记一次线上接口慢查询问题排查
- 【分类模型】Q 型聚类分析
- Esp32 esp-idf GPIO key interrupt response
- 3. Disabling copy construction
- ESP32 - ULP 协处理器在低功耗模式下读片内霍尔传感器HALL SENSOR
- 【微信小程序】视图容器和基本内容组件
猜你喜欢

8 figures | analyze Eureka's first synchronization registry

ctfhub-端口扫描(SSRF)

ctfshow-web352,353(SSRF)

问题:OfficeException: failed to start and connect(三)

Introduction to spark (one article is enough)

(I) apple has open source, but so what?

【微信小程序】一文解决button、input、image组件
![[wechat applet] to solve button, input and image components](/img/7f/a61ee2f610b2f0f9fb0b34cb960f81.jpg)
[wechat applet] to solve button, input and image components

Easynvs cloud management platform function reconfiguration: support adding users, modifying information, etc

Product learning (III) - demand list
随机推荐
【微信小程序低代码开发】二,在实操中化解小程序的代码组成
在长城证券上做基金定投安全吗?
Several ways of gson's @jsonadapter annotation
Router 6/ 以及和Router5 的区别
Embedded system
rclone常用子命令中文解释
问题:OfficeException: failed to start and connect(三)
[FPGA frame difference] FPGA implementation of frame difference target tracking based on vmodcam camera
MySQL data type learning notes
Is it suitable for girls to study product manager? What are the advantages?
如何进入互联网行业,成为产品经理?没有项目经验如何转行当上产品经理?
在支付宝上买基金安全吗?哪里可以买基金
Esp32 - ULP coprocessor reading Hall sensor in low power mode
【Tikhonov】基于Tikhonov正则化的图像超分辨率重建
Problem solving: officeexception: failed to start and connect (I)
K8S搭建Redis集群
If I am in Guangzhou, where can I open an account? Is it safe to open an account online?
[wechat applet] how to build a building block development?
Database objects: view learning records
ctfshow-web352,353(SSRF)