简体   繁体   中英

pagination in struts

I have a requirement where I have to fetch some records from the database and then I have to show 50 records per page on a JSP. The page will be having First, Previous, Next and Last buttons on the screen. Has anyone implemented similar functionality in struts or similar framework? also i dont want to get all records at once. please guide me how to implement?

Thanks in Advance

I use the Displaytag library for this. It works great in combination with Struts and jsp and provides sorting and pagination.

Use Strust2 criteria API to set max results

List<Class_Name> records = new ArrayList<Class_Name>();
private static SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session s = sf.openSession();
Criteria cr = s.createCriteria(Class_Name.class);
cr.setMaxResults(50);


records = cr.list();
s.close();

Use Struts 2 Jq Grid plugin It is plugin designed for struts2 .. display tag is depreciated. You can achieve by just the use struts2 jqgrid tags and there are lot of other features also there

maybe you can try some JQuery plugin that handles all client-side processing and take data from the server-side code. You migh try http://www.datatables.net/ because it handles pagination, filtering, ordering and has much more features. Here is explained how you can integrate DataTables with java servlet application http://www.codeproject.com/KB/java/JQuery-DataTables-Java.aspx .

1)in Action Class Calculate total number of pages in action(fetch it from it from database and calculate like totalPages=totalEntries/pageSize)

2) send pageNumber from jsp(while user click on page no), send pageSize from jsp(if user has to specify pageSize) or from action to Business. String query = "select empid, ename from employee by joindate desc limit " + start + "," + pageSize;

Calculate Start like int start = (pageNumber * pageSize - pageSize);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM