Java Reference
In-Depth Information
resultSet = statement.executeQuery(query);
JRResultSetDataSource resultSetDataSource =
new JRResultSetDataSource(resultSet);
model.put("datasource", resultSetDataSource);
"datasource", resultSetDataSource);
datasource", resultSetDataSource);
return model;
}
public void setDataSource (DataSource dataSource)
{
this.dataSource=dataSource;
}
}
Note that our implementation of the handleRequest() method is very simple. It
returns a new instance of org.springframework.web.servlet.ModelAndView . We
pass the view name �defined in the application context) and a map containing the
data to be displayed to the constructor of ModelAndView , and return it.
The getModel() method of JasperSpringController executes an SQL query in the
database and populates an instance of JRResultSetDataSource with the results.
Finally, we need to write a JSP that will invoke JasperSpringController .
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
"-//W3C//DTD HTML 4.01 Transitional//EN">
-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Generate Report</title>
</head>
<body>
Click on the button to generate the report.
<form name="reportForm" action="jasperSpring/report" method="post">
<input type="submit" name="submitButton" value="Submit"/>
</form>
</body>
</html>
Notice that no special JSP tag libraries are needed to integrate with Spring. After we
deploy our web application and direct our browser to http://localhost:8080/
jasperspring/generate_report.jsp , we should see a web page like the following:
 
Search WWH ::




Custom Search