I just gave a quick look to the example, but basically it's telling you how to do pagination on the client side, not how to retrieve paginated results from a database.
If I were you I would...
1- use Spring Boot instead of Spring
2- use thymeleaf rather than
jsp
3- use Spring Data
When using Spring Data you can make your repositories support the Pageable class and then you just need to use it in your controllers. I don't have enough time to explain all of it, but i can show you a few fragments of my code and then you could study the docs.
Controller:
To make it short: Spring Data repositories give you out of the box support for the Pageable class, which tells them what kind of LIMIT clause to use with the database. They will also do a count for you to retrieve the total number of pages.
On the controller side, by putting Pageable in the method signature, Spring will search for HTTP params called "size" and "page".
For example: www.mysite.com/users?page=1&size=10
will tell Spring to fetch the second page (it's 0-based), considering 10 elements as page size
The UserRepository in my code returns a Page<User> object, which contains info about the total number of pages and a list of users from 11 to 20 in this case.
I can't show you any code for DataTables on the client side because I render the pagination server side with a templating engine, so it's up to you to make this work.