Data page display with JSP

xiaoxiao2021-03-06  107

The Internet era is actually the era of data. Building a large-scale e-commerce system must involve a large amount of data, the page display of data is frequently encountered, if each programmer should consider the acquisition and processing of data. Details, it will be a thing that is bad and chaotic, similar to paging shows that this control logic with public characteristics must be implemented in the Horizonal Layer layer.

This paper gives a reusable, easy-to-transplantation of the use of JSP processing paging in a step-by-step manner.

If the data corresponding to various business logic entities is called "entity data", the paging display logic is packaged is "control data" for control entity data (hereinafter used in the following statements).

First let us build a PageControl object to encapsulate some of the key "control data" involved in paging.

Specific description is as follows:

Public int curpage; // is currently the first few packets; / / a total of how many page public int maxrowcount; // How many rows of public int RowsPerpage; / / How many rows of public YourDataType yourData; // Load each Page data About the "physical data" carrier of the "entity data" to be displayed per page, the implementation method is a variety of ways, for example, in the IBM e-commerce system MPE is in the form of bean, this is an object-oriented implementation, a relatively simple The implementation can be used in Java.util.Vector, etc., in order to avoid distracting the attention of the core problem, here is abstract with YOUDATATYPE.

Public void countmaxpage () {// calculate the total number of pages according to the total number of lines

IF (this.maxrowcount% this.rowsperpage == 0) {

THIS.MAXPAGE = this.maxrowcount / this.rowsperpage;

} else {

THIS.MAXPAGE = this.maxrowcount / this.rowsperpage 1;

}

}

This.RowsPerPage actually obtained from the configuration file, the advantage of doing this is that the program can read in the run to implement dynamic (again) configuration, and a brief approach is to write directly in the program. Public pageControl (YourPersistencelayer Yourpl) This is a configuration function for YourPersistencelayer. Persistencelayer is a layer directly with the database, and different companies have different implementations. For example, Microsoft ADO can be seen as a persistencelayer, IBM In its MPE system, a huge Persistencelayer is also implemented, and a speculative approach is not Persistencelayer, or it can be said to be desadcussion, so that it will reduce the stability, reusability, and scalability of the system. Specifically, you can refer to Appendix Document. In this constructor, there are several main operations:

THIS.MAXROWCOUNT = YourPl.getavailableCount (); // Get the total number of minutes

THIS.YOODATA = YourPl.getResult (); // Get data to be displayed on this page

This.countmaxPage (); // calculate the total number of pages

There is another detail about this.yourdata: When you get "physical data" from the database, there are usually two ways: (a) acquire all data at once; (b) obtain this page each time according to the current page number Data, give additional data; considering data is often large or even massive, if one-time acquisition, then these data must occupy a large number of server memory resources, so that system performance is greatly reduced, so recommended method (a) Next The work can be handed over to Servlet and JSP, just in the service () method of the servlet:

PageControl PagectL = YourBusinessObject.listdata (Req.getParameter ("JUMPPAGE"));

Req.settribute ("PagectL", PagectL;

Note: YourBusinessObject encapsulates business logic, an object in Business Lyer, using OOAD method, package business object, forming a solid business logic layer on Persistent Layer is also a key to building large e-commerce architectures. This article is only paging processing, which is not discussed in detail.

In each JSP page that you want to implement flip display data, our work is also very simple, and its code is formulated:

<% IF (Pagectl.maxPage! = 1)) {%>

<%}%>

Description: If (pagectl.maxpage! = 1) implements such a logic: If the data is not enough, then you don't have to turn the page display. We noticed <% @ include file = "/ YourPath / PageMan.jsp"%> This makes the real flip section are fully reused.

So what do Pageman.jsp done? It achieves the first page of people who often do flip processing, unfamiliarless logic (a) cannot be forwarded forward; (b) Cannot turn back backwards when the last page; at the same time, the page can be played, the specific code is as follows :

Per page <% = pagectl.rowsperpage%>

A total of <% = pagectl.maxrowcount%>

No. <% = Pagectl.curpage%> Page

A total of <% = pagectl.maxpage%> page

<% IF (pagectl.curpage == 1) {OUT.PRINT ("Home Previous");} else {%>

Homepage

Previous page

<%}%>

<% IF (Pagectl.curpage) {OUT.PRINT ("Next Last");} else {%>

Next page

last page

<%}%>

Turn to Page

The appearance of the following figure will be present on the page, as for the formation of beautification, is the work of the art.

Finally attached a JavaScript public function for page jump:

Function JUMPING () {

Document.pageform.submit ();

Return;

}

Function Gotopage (PAGENUM) {

Document.pageform.jumppage.value = Pagenum;

Document.pageform.submit ();

Return;

}

转载请注明原文地址:https://www.9cbs.com/read-123467.html

New Post(0)