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.