Simple implementation of JSP paging display effect
This article mainly introduces in detail the simple implementation of JSP paging display effect. It has certain reference and learning value for JSP. Friends who are interested in JSP can refer to this article.
This article The example shares the specific code for the JSP paging display effect for your reference. The specific content is as follows
1. Mysql's limit keyword (DAO)
select * from tablename limit startPoint, numberPerPage;
tablename It is the name of the table to be displayed in pages;
startPoint is the starting position -1;
numberPerPage is the number of items displayed on one page.
For example: select * from comment limit 20,5;
extracts comments 21~25 from the comment table:
2. jQuery load function (page JS)
The limit keyword of MySQL can complete the extraction of records in a certain range (n, n+m], which means that two parameters are needed to Determine the content displayed on a certain page, that is, "page x" and the number displayed on each page.
The number displayed on each page can be set in the program or by the user. The parameter "page x" must be given by the user. When the user clicks the page number, next page/previous page button or jumps to a certain page, the parameter "page x" needs to be sent to the server so that Extract records.
function goToPage(page){ $('body').load("getComments.do?page=" + page); }
Or, if both parameters are specified by the user, the function can be written as:
function goToPage(page, numberPerPage){ $('body').load("getComments.do?page=" + page + "&npp=" + numberPerPage); }
3, servletReceive the parameters and organize them. Content (servlet file)
The servlet learns that the user wants to browse page X and how many records are displayed on one page by accepting the page and npp parameters in the request object from the jsp page.
int page = Integer.parseInt(req.getParameter("page"));
4. The servlet calculates the displayed page list
Generally, about 10 pages are displayed at a time, that is, if you are on page 52 now, then the optional page list is 50 , 51, 52... Until 60.The calculation method is, assuming that it is on page x, the starting value is x/10*10, the premise is that x>10. #int start = 1; if(page >= 10){ start = page/10 * 10; }
There are two special cases:
① The total number of pages is less than 10
② The number of pages is not an integral multiple of 10
The number of pages will appear If the list is less than 10, it is easy to handle. Just add if
conditional judgment. The approximate code is as follows: int total = sm.getCommentCount();
int totalPage = total/itemsPerPage;
if(total % itemsPerPage != 0){
totalPage += 1;
}
Vector<Integer> pageArr = new Vector<Integer>();
int start = 1;
if(page >= 10){
start = page/10 * 10;
}
int num = start;
while(!(num > totalPage || num > start + 10)){
pageArr.add(new Integer(num));
++num;
}
Through 4 we get a calculated page list pageArr, which shows which pages we should display for the current page so that users can directly click on it in the servlet. Put it into the response object, along with page (current page number) and totalPage (maximum page number) to help us make some judgments
##<!-- 上一页 按钮 --> <p id="pageControl"> <c:choose> <c:when test="${page != 1}"> <a href="checkComments.do?page=${page-1}" rel="external nofollow" ><input type="button" name="lastPage" value="上一页" /></a> </c:when> <c:otherwise> <input type="button" disabled="true" name="lastPage" value="上一页" /><!-- 为了要那个灰掉的button --> </c:otherwise> </c:choose> <!-- 页数列表 --> <c:forEach items="${pageList}" var="item"> <c:choose> <c:when test="${item == page}"> <a href="checkComments.do?page=${item}" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="currentPage">${item}</a> </c:when> <c:otherwise> <a href="checkComments.do?page=${item}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >${item}</a> </c:otherwise> </c:choose> </c:forEach> <!-- 下一页 按钮 --> <c:choose> <c:when test="${page != totalPages}"> <a href="checkComments.do?page=${page+1}" rel="external nofollow" > <input type="button" name="nextPage" value="下一页" /> </a> </c:when> <c:otherwise> <input type="button" disabled=true name="nextPage" value="下一页" /><!-- 为了要那个灰掉的button --> </c:otherwise> </c:choose> <!-- 直接跳转 --> 共${totalPages}页 -向<input type="text" id="jumpTo" />页 <input type="button" value="跳转" onclick="jumpTo(${totalPages})" /> </p>
The js function used.
function jumpTo(maxPage){ var page = $("#jumpTo").val(); if(page > maxPage || page < 1){ alert("对不起,无法到达该页") }else{ $('body').load('checkComments.do?page=' + page); } }
6. CSS enhancement effect
In order to highlight the page number we are currently on, we specially made a judgment in the above code:
<c:when test="${item == page}"> <a href="checkComments.do?page=${item}" class="currentPage">${item}</a> </c:when>
.currentPage{ font-weight:bold; color:#ff9a00; }
#jumpTo{ width:20px; }
7. Improvement
Although it is more convenient to use the a tag method to make links, underlines will appear, which feels very unstylish. You can use css to eliminate it, or add some changes when hovering.
#pageControl a { text-decoration:none; }
The above is the entire content of this article, I hope it will be helpful to everyone’s study! !
JSP Basics Introduction
JsPlumb Flow Chart Experience Summary
jsp implements the paging function of upper and lower pages
The above is the detailed content of Simple implementation of JSP paging display effect. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



You may have encountered the problem of green lines appearing on the screen of your smartphone. Even if you have never seen it, you must have seen related pictures on the Internet. So, have you ever encountered a situation where the smart watch screen turns white? On April 2, CNMO learned from foreign media that a Reddit user shared a picture on the social platform, showing the screen of the Samsung Watch series smart watches turning white. The user wrote: "I was charging when I left, and when I came back, it was like this. I tried to restart, but the screen was still like this during the restart process." Samsung Watch smart watch screen turned white. The Reddit user did not specify the smart watch. Specific model. However, judging from the picture, it should be Samsung Watch5. Previously, another Reddit user also reported

Speaking of ASSASSIN, I believe players will definitely think of the master assassins in "Assassin's Creed". They are not only skilled, but also have the creed of "devoting themselves to the darkness and serving the light". The ASSASSIN series of flagship air-cooled radiators from the appliance brand DeepCool coincide with each other. Recently, the latest product of this series, ASSASSIN4S, has been launched. "Assassin in Suit, Advanced" brings a new air-cooling experience to advanced players. The appearance is full of details. The Assassin 4S radiator adopts a double tower structure + a single fan built-in design. The outside is covered with a cube-shaped fairing, which has a strong overall sense. It is available in white and black colors to meet different colors. Tie

With the arrival of spring, everything revives and everything is full of vitality and vitality. In this beautiful season, how to add a touch of color to your home life? Haqu H2 projector, with its exquisite design and super cost-effectiveness, has become an indispensable beauty in this spring. This H2 projector is compact yet stylish. Whether placed on the TV cabinet in the living room or next to the bedside table in the bedroom, it can become a beautiful landscape. Its body is made of milky white matte texture. This design not only makes the projector look more advanced, but also increases the comfort of the touch. The beige leather-like material adds a touch of warmth and elegance to the overall appearance. This combination of colors and materials not only conforms to the aesthetic trend of modern homes, but also can be integrated into

With its compact size, the ITX platform has attracted many players who pursue the ultimate and unique beauty. With the improvement of manufacturing processes and technological advancements, both Intel's 14th generation Core and RTX40 series graphics cards can exert their strength on the ITX platform, and gamers also There are higher requirements for SFX power supply. Game enthusiast Huntkey has launched a new MX series power supply. In the ITX platform that meets high-performance requirements, the MX750P full-module power supply has a rated power of up to 750W and has passed 80PLUS platinum level certification. Below we bring the evaluation of this power supply. Huntkey MX750P full-module power supply adopts a simple and fashionable design concept. There are two black and white models for players to choose from. Both use matte surface treatment and have a good texture with silver gray and red fonts.

What happens when the desktop layout is locked? When using the computer, sometimes we may encounter the situation where the desktop layout is locked. This problem means that we cannot freely adjust the position of desktop icons or change the desktop background. So, what exactly is going on when it says that the desktop layout is locked? 1. Understand the desktop layout and locking functions. First, we need to understand the two concepts of desktop layout and desktop locking. Desktop layout refers to the arrangement of various elements on the desktop, including shortcuts, folders, widgets, etc. we can be free

A large model that can automatically analyze the content of PDFs, web pages, posters, and Excel charts is not too convenient for workers. The InternLM-XComposer2-4KHD (abbreviated as IXC2-4KHD) model proposed by Shanghai AILab, the Chinese University of Hong Kong and other research institutions makes this a reality. Compared with other multi-modal large models that have a resolution limit of no more than 1500x1500, this work increases the maximum input image of multi-modal large models to more than 4K (3840x1600) resolution, and supports any aspect ratio and 336 pixels to 4K Dynamic resolution changes. Three days after its release, the model topped the HuggingFace visual question answering model popularity list. Easy to handle

In the current era of rapid technological development, laptops have become an indispensable and important tool in people's daily life and work. For those players who have high performance requirements, a laptop with powerful configuration and excellent performance can meet their hard-core needs. With its excellent performance and stunning design, the Colorful Hidden Star P15 notebook computer has become the leader of the future and can be called a model of hard-core notebooks. Colorful Hidden Star P1524 is equipped with a 13th generation Intel Core i7 processor and RTX4060Laptop GPU. It adopts a more fashionable spaceship design style and has excellent performance in details. Let us first take a look at the features of this notebook. Supreme equipped with Intel Core i7-13620H processing

In today's smartphone market, screen quality has become one of the key indicators to measure the overall performance of a mobile phone. iQOO's Neo series has always been committed to providing users with excellent gaming experience and visual enjoyment. The latest product iQOO Neo9SPro+ uses a "Three Good Eye Protection Gaming Screen". Next, let's take a look at the quality of this screen. How brilliant. iQOO Neo9S Pro+ is equipped with a 1.5 KOLED e-sports direct screen, which supports flagship LTPO adaptive refresh rate from 1Hz to 144Hz, which means that it can achieve ultra-low power standby state when displaying static content, and it can also be intelligent during gaming. Switch to dynamic high from 90Hz to 144Hz
