Spring 3 MVC framework provides supporting classes/annotations that can prove to be real “gems” during development of your web application. I’ll be covering a few of them, the first is org.springframework.bean.support.PagedListHolder.
As per documentation, PagedListHolder is a simple state holder bean for handling lists of objects, separating them into pages. It has setter methods to indicate page size, page number. For e.g in your specific Controller class you can add the following code snippet to create paginated data that can be accessed in a JSP or any other View.
String srchkey= request.getParameter("srchkey");
if (srchkey!= null)
{
PagedListHolder<Product> productList = new PagedListHolder<Product>(getProductList(srchkey));
productList.setPage(0);
productList.setPageSize(4);
return new ModelAndView("listProducts", "productList", productList);
}
else
{
String page = request.getParameter("page");
PagedListHolder productList = (PagedListHolder)request.getSession().getAttribute("productList");
if ("next".equals(page))
productList.nextPage();
else if ("previous".equals(page))
productList.previousPage();
return new ModelAndView("listProducts", "productList", productList);
}