How to display query results by page in Struts

Source: Internet
Author: User

Messagelist. do-> messagelist. jsp

Use messagelist. do? Start = 0 to display the first page

Parameter description:

List: Information list

Start: start position

Page: Number of information displayed on each page

Previous: Start position of the previous page

Next: Start position of the next page

The perform in MessageListAction is written as follows:

Bytes ------------------------------------------------------------------------------------

Int start = Integer. parseInt (request. getParameter ("start "));

System. out. println ("Start:" + start );

Int page = 4;

// Create a message list

Message [] list = new Message [16];

For (int I = 0; I <list. length; I ++ ){

List [I] = new Message (I, "message" + I );

}

Request. setAttribute ("list", list );

Request. setAttribute ("start", new Integer (start ));

Request. setAttribute ("page", new Integer (page ));

// If there is a previous page, set the previous variable

Int previous = start-page;

If (previous> = 0 ){

Request. setAttribute ("previous", new Integer (previous ));

System. out. println ("previous:" + previous );

}

// If there is a next page, set the next variable

Int next = start + page;

If (next <list. length ){

Request. setAttribute ("next", new Integer (next ));

System. out. println ("next:" + next );

}

Return (mapping. findForward ("success "));

Bytes ------------------------------------------------------------------------------------

The content in messagelist. jsp is as follows:

Bytes ------------------------------------------------------------------------------------

<Logic: iterate id = "message" name = "list" offset = "start" length = "page">

<Br>

ParamId = "id" paramName = "message" paramProperty = "id"

Page = "/messagedetail. do">

<Bean: write name = "message" property = "name"/>

</Html: link>

</Logic: iterate>

<Logic: present name = "previous">

<Br>

ParamId = "start" paramName = "previous"

Page = "/messagelist. do">

Previous Page

</Html: link>

</Logic: present>

<Logic: present name = "next">

<Br>

ParamId = "start" paramName = "next"

Page = "/messagelist. do">

Next Page

</Html: link>

</Logic: present>

Bytes ------------------------------------------------------------------------------------

This example illustrates the usage of logic: iterate in pages.

Every time messagelist. do processes all messages, the performance can be optimized.

For example, store the message array in the session.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.