当前位置:网站首页>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 .
边栏推荐
- Docker installation and deployment redis
- Is the account opening of Huafu securities safe and reliable? How to open Huafu securities account
- 发现了一个 MySQL 的巨坑:update 更新别再用影响行数做判断了!!!
- Chinese explanation of common rclone subcommands
- 【微信小程序低代码开发】二,在实操中化解小程序的代码组成
- How to use Alibaba vector font files through CDN
- Which securities company does qiniu school cooperate with? Is it safe to open an account?
- 转行做产品经理,如何挑选产品经理课程?
- Find the original array for the inverse logarithm
- 为什么这么多人转行产品经理?产品经理发展前景如何?
猜你喜欢

ctfshow-web354(SSRF)

【图像处理】图像直方图均衡化系统含GUI界面

代码实战——从零开始搭建自己的Diffusion models/Score-based generative models

Product learning (III) - demand list

ESP32 ESP-IDF GPIO按键中断响应

未来互联网人才还稀缺吗?哪些技术方向热门?

Spark入门(一篇就够了)

2022 年江苏省职业院校技能大赛(中职) 网络搭建与应用赛项公开赛卷

Product learning (I) - structure diagram

Pourquoi tant de gens sont - ils devenus des gestionnaires de produits? Quelles sont les perspectives de développement des gestionnaires de produits?
随机推荐
Rclone Chinese document: a collection of common commands
SQL language learning record I
用手机在指南针上开户靠谱吗?这样有没有什么安全隐患
Grain Mall - environment (p1-p27)
buildroot override 机制
C语言实现【扫雷游戏】完整版(实现源码)
Embedded system
【微信小程序】一文解决button、input、image组件
ESP32 ESP-IDF ADC监测电池电压(带校正)
Esp32 monitors the battery voltage with ULP when the battery is powered
Easynvs cloud management platform function reconfiguration: support adding users, modifying information, etc
灰度何以跌下神坛?
Principle of introducing modules into node
[wechat applet] view container and basic content components
软件工程复习
ESP32 ESP-IDF GPIO按键中断响应
Chinese explanation of common rclone subcommands
【LINGO】求无向图的最短路问题
(上)苹果有开源,但又怎样呢?
ESP32在电池供电时用ULP监测电池电压