prashantckc Posted October 19, 2010 Share Posted October 19, 2010 Hi All,I have integrated the Jasper with Spring and also tested a sample report, which is working fine. These are the components which are used1. Web.xml {Having the Servlet Mapping}2. jasperSpring-servlet.xml {This contains the Data Souce and the Source Name}3. Simple JSP with Submit Button.The Code is show below Can you please let me know how we can use the File Virtualizer in this case as I am not able to understand where exactly the filling is taking place. This code is from the example of integrating Spring with Jasper (From the Book Java Reports for Java Developers)Code:package net.ensode.jasperbook.spring;import java.io.IOException;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.HashMap;import java.util.Map;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.sql.DataSource;import net.sf.jasperreports.engine.JRParameter;import net.sf.jasperreports.engine.JRResultSetDataSource;import net.sf.jasperreports.engine.fill.JRFileVirtualizer;import org.springframework.web.servlet.ModelAndView;import org.springframework.web.servlet.mvc.Controller;public class JasperSpringController implements Controller { private DataSource dataSource; public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, ClassNotFoundException, SQLException { return new ModelAndView("report", getModel()); } private Map getModel() throws ClassNotFoundException, SQLException { Connection connection; Statement statement; ResultSet resultSet; HashMap model = new HashMap(); String query = "select * from tb_fxstp_contracts"; System.out.println(" Getting the DataBase Connection....................."); connection = dataSource.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery(query); JRResultSetDataSource resultSetDataSource = new JRResultSetDataSource( resultSet); model.put("dataSource", resultSetDataSource); return model; } public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; }} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now