当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Notes on probability theory
![[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines](/img/34/d2efae5b283cdc130d55f52cdff76d.png)
[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines

Is it suitable for girls to study product manager? What are the advantages?

Esp32 esp-idf GPIO key interrupt response

Jena default inference query based on OWL

解决无法读取META-INF.services里面定义的类

Fix the problem that the AI video intelligent platform easycvr device video cannot be played

产品学习(三)——需求列表

Figure out the difference between event coordinates screenx, clientx, pagex and offsetx

DC-4 target
随机推荐
[lingo] find the minimum connection diagram of seven cities to minimize the price of natural gas pipelines
广发证券开户是安全可靠的么?怎么开广发证券账户
Using fuseki query when there are multiple models in TDB
Terminology description in the field of software engineering
【推荐技术】基于协同过滤的网络信息推荐技术matlab仿真
rclone中文文档:常用命令大全
Several ways of gson's @jsonadapter annotation
[recommendation technology] matlab simulation of network information recommendation technology based on collaborative filtering
ESP32 - ULP 协处理器在低功耗模式下读片内霍尔传感器HALL SENSOR
2022 年江苏省职业院校技能大赛(中职) 网络搭建与应用赛项公开赛卷
Solve the problem that the class defined in meta-inf.services cannot be read
开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
[wechat applet] view container and basic content components
Pourquoi tant de gens sont - ils devenus des gestionnaires de produits? Quelles sont les perspectives de développement des gestionnaires de produits?
rclone配置minio及基本操作
TDB中多个model情况下使用fuseki查询
图解事件坐标screenX、clientX、pageX, offsetX的区别
Programming examples of stm32f1 and stm32subeide infrared receiving and decoding of NEC protocol
解决kaniko push镜像到harbor时报错(代理导致):unexpected status code 503 Service Unavailable
Methods of downloading Foreign Periodicals