Web application paging technology

xiaoxiao2021-03-06  73

I saw a lot of guidance for providing Web page pages technology online, but I feel that the reference value is not big, so I sumly the experience of others and rewrite it again.

Most of the website architecture is based on MVC, usually JSP as a display layer, or with template technology as a display layer, this layer will display the total number of query records, and the current page, and page navigation, and display change record (Model) ), the servlet is usually used as a control layer to collect query conditions, call the business bean, complete the page query, and return the result to the display layer. For paging, the main tasks of each level are as follows:

Display layer:

Take the total number of records and display it;

Indicates current in the shorter page

Show flip page navigation strips, such as flipping like Google, or flip style like Yahoo

Remove the record set and display it, usually, a page shows 10-30, and this is configurable.

Control layer:

When the query is inquiry, the user entered the query bar, usually the form is queryvalue in the session, so that the query condition is retrieved when the next page is turned down.

If it is the first query, call the business bean, you need to query the total number of records and query the result set of the first page and pass it to the display layer.

If it is a subsequent page, you need to call the business bean query to query the result set within the specified range and pass it to the display layer.

Business bean:

Business bean provides a total number of conditions in accordance with QueryValue

Business bean provides results set according to QueryValue, and STARTINDEX, EndIndex.

Now, an example is made from the specific implementation of the business bean, the control layer, and the display layer, and I hope this example can be copied.

Business bean:

Public Class BusinuessFacade

{

...........

Public Int QueryBooksize (BookQueryValue QV) throws ....

{

}

Public BookValueObject QueryBooks (BookQueryValue QV, Int StartIndex, Int endindex) throws ....

{

}

}

Public Class BookQueryValue

{

Public String Name;

Public String ISBN

..........

}

Control layer, use Servervet

Public Class BookQueryServelt

{

Doget (httpservletRequest Request, HttpservletResponse Response ....

{

String offset = Request.getParameter ("Pager.offset");

INT StartIndex = 0;

INT endIndex = 0;

BookQueryValue QV = NULL;

HttpSession session = request.getations ();

IF (offset == null)

{

// First query, need to find the total number of records

QV = CREATEQUERYVALUE (REQUEST);

INT size = facade.querybooksize (qv);

Session.setttribute ("Resultsize", New Integer (size);

Session.SetAttribYTE ("QueryValue", QV);

STARTINDEX = 1;

EndIndex = consTs.max_page_items;

IF (EndIndex> size) endindex = size;

}

Else

{

StartIndex = (New Integer (Offset)). INTVALUE () 1;

INT size = ((Integer) session.getattribute ("resultsize")). INTVALUE ();

EndIndex = StartIndex Consts.max_page_items; if (endindex> size) endindex = size;

QV = (BookQueryValue) session.getattribute ("queryvalue");

}

BookValueObject [] vos = facade.querybooks (QV, StartIndex, EndIndex);

Request.setattribute ("Result", VOS);

GotoQueryResultPage (Request);

}

}

Display layer: The above two layers have already prepared data, now use

Pager tag

http://jsptags.com/tags/naVigation/pager/download.jsp) to help complete the display

<%

//initialization

String contextpath = request.getContextPath ();

INT size = ((Integer) session.getattribute ("resultsize")). INTVALUE ();

String actionPath = contextPath "/ bookqueryservlet";

%>

MaxPageItems = "<% = consts.max_page_items%>" // How many records are displayed per page

MaxIndexpages = "<% = consts.max_index_page%>" // Turn the page navigation bar display how many pages

Isoffset = "<% = true%>"

URL = "<% = ActionPath%>" // ServelT called when page

Export = "offset, currentpagenumber = panumber"

Scope = "request"

>

<% = vo.name%>

<% = Vo.isisbn%>

The display layer uses the Struts tag library, and

Pager TAG technology, you need to understand this, but also recommend you to understand these technologies.

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

New Post(0)