I've had a look at this example: http://helptodeveloper.blogspot.com/2010/02/jasper-reports-with-pagination.html and checked the webapp demo included in the JasperReports package (in particular the viewer.jsp).
I've tried to achieve something similar using Spring MVC.
In my controller class I've modified my request-handling method this way:
@RequestMapping("/report")
public ModelAndView showHtmlReport(HttpServletRequest request,
HttpServletResponse response,
@RequestParam(value = "page", required = false) String pageIndex,
ModelMap model) {
// do something...
if (StringUtils.isNotBlank(pageIndex)
&& StringUtils.isNumeric(pageIndex)) {
model.put("page_index", new Integer(pageIndex));
}
// do something else...
return new ModelAndView("htmlReport", model);
}
Then I've extended the standard JasperReportsHtmlView provided by Spring, overriding the renderReport method:
@Override
protected void renderReport(JasperPrint populatedReport,
Map<String, Object> model, HttpServletResponse response)
throws Exception {
// check something...
if (model.containsKey("page_index")) {
Map<net.sf.jasperreports.engine.JRExporterParameter, Object> expParams =
this.getConvertedExporterParameters();
expParams.put(
net.sf.jasperreports.engine.JRExporterParameter.PAGE_INDEX,
model.get("page_index"));
}
// check something else...
super.renderReport(populatedReport, model, response);
}
NOTE: I actually extended the html-view class for another reason ( Images not shown in JasperReports' html report ), but following the same approach I solved also this problem.
NOTE pt.2: I'm new to Spring Framework, so if my answer is not completely correct... Try to understand me! :)