One implementation of struts paging! (2)

Source: Internet
Author: User

Query the code snippet of an action

Public actionforward execute (
Actionmapping mapping,
Actionform form,
Httpservletrequest request,
Httpservletresponse response)
Throws exception {
Base queryform = (base) form;

If (! Queryform. getname (). Equals ("")){
Pagecontroller Pc = new pagecontroller ();
Employeebase service = new employeebase ();
Arraylist result = (arraylist) service. Search (queryform, PC );

Httpsession session = request. getsession ();

Session. setattribute ("queryform", queryform );
Session. setattribute ("pagecontroller", Service. getpagecontroller ());

Request. setattribute ("queryresult", result );
Request. setattribute ("pagecontroller", Service. getpagecontroller ());
Return Mapping. findforward ("haveresult ");
} Else {
Return Mapping. findforward ("noresult ");
}



 
}

(3) flip the code snippet of the action

Public actionforward execute (
Actionmapping mapping,
Actionform form,
Httpservletrequest request,
Httpservletresponse response)
Throws exception {
 

File: // read paging Parameters

Turnpageform = (turnpageform) form;

File: // retrieve the query information from pagecontroller and process the query result using the API provided by bean.

Httpsession session = request. getsession ();
Pagecontroller Pc = (pagecontroller) Session. getattribute ("pagecontroller ");
Base queryform = (base) Session. getattribute ("queryform ");

 
PC. setcurrentpage (turnpageform. getviewpage ());

Employeebase service = new employeebase ();

Arraylist result = (arraylist) service. Search (queryform, PC );

File: // write data to the request according to the parameter

Request. removeattribute ("queryresult ");
Request. removeattribute ("pagecontroller ");
Request. setattribute ("queryresult", result );
Request. setattribute ("pagecontroller", PC );

File: // forward to the display page



Return Mapping. findforward ("haveresult ");




 
}

(4) fragments in the database access Bean

Public Collection Search (base, pagecontroller PC)
Throws sqlexception {
Arraylist EMPs = new arraylist ();
Resultset rs = getsearchresult (base );

Rs. Absolute (-1 );
PC. settotalrowsamount (Rs. getrow ());
Setpagecontroller (PC );
If (Rs. getrow ()> 0 ){

Rs. Absolute (PC. getpagestartrow ());

Do {
System. Out. println ("in loop" + Rs. getrow ());

Base B = new base ();
B. setname (Rs. getstring ("name "));
B. setidcard (Rs. getstring ("idcard "));
System. Out. println ("from DB:" + Rs. getstring ("idcard "));
EMPs. Add (B );
If (! Rs. Next ()){
Break;
}
} While (Rs. getrow () <(PC. getpageendrow () + 1 ));
}
Return EMPs;
}

(5) code snippets in pages in JSP

<Bean: write name = "pagecontroller" property = "Description"/>

<Logic: equal name = "pagecontroller" property = "hasprevious" value = "true">
<A href = "turnpage. do? Viewpage = <Bean: write name = "pagecontroller" property = "previouspage"/> "class =" A02 ">
Previous
</A>
</Logic: equal>

<Logic: equal name = "pagecontroller" property = "hasnext" value = "true">
<A href = "turnpage. do? Viewpage = <Bean: write name = "pagecontroller" property = "nextpage"/> "class =" A02 ">
Next
</A>
</Logic: equal>

 

In this way, the page flip function can be displayed to the client as you like.

Related Article

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.