How To Limit The Html Table Records In Each Page
Solution 1:
You can use 'display' tag which provides pagination, sorting, exporting. In your current code, you are iterating a result set and creating table rows. Having Java code in JSP is not the best practice. Move that into a servlet and create a collection of beans by iterating the result set and set the collection in request scope or session scope(If you want to avoid multiple DB hits).
Sample Usage (From display tag site)
<display:tablename="sessionScope.test"pagesize="10"><display:columnproperty="id"title="ID" /><display:columnproperty="name" /><display:columnproperty="email" /><display:columnproperty="status" /></display:table>
Here the 'test' is the name of the attribute that stores a collection. The 'property' attributes for column tag represent the properties of your bean contained in the collection. 'pagesize' specifies the pagination size that the number of items to be displayed in a page.
For more info: http://displaytag.sourceforge.net/1.2/index.html
Solution 2:
I know that you are looking for a back-end solution, but how about making it easier for the user (by not forcing page refresh on each request) and have a js solution (a js pagination solution)?
A list of jQuery pagination solutions
- List of jQuery pagination plugins
- 15 more jQuery pagination plugins
- Another one (includes pagination + sorting)
- Another 20 Table pagination plugins
Again, this is only a suggestion, go for whatever works for you (and your users) best.
As requested: see a good beginner tutorial or Another one.
Solution 3:
What you want is a pagination code example. Here's one I found online: http://www.easywayserver.com/blog/jsp-pagination/ There are lots of examples of this and you'll have to find which one formats your nav links the way you like them
Post a Comment for "How To Limit The Html Table Records In Each Page"