2-It download it as pdf in chrome.
package esh.view;
import esh.model.AppModuleImpl;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.view.JasperViewer;
import oracle.jbo.client.Configuration;
@WebServlet(name = "MultiReportServletJasper", urlPatterns = { "/multireportservletjasper" })
public class MultiReportServletJasper extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
protected Connection getConnection() {
PreparedStatement st = null;
String amDef = "esh.model.AppModule";
String config = "AppModuleLocal";
AppModuleImpl am = (AppModuleImpl ) Configuration.createRootApplicationModule(amDef, config);
st = am.getDBTransaction().createPreparedStatement("select 1 from dual", 0);
Connection conn = null;
try {
conn = st.getConnection();
return conn;
} catch (SQLException e) {
}
return null;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String var0 = "";
String reportName = "";
try {
reportName = request.getParameter("reportName");
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType(CONTENT_TYPE);
Map parameters = new HashMap();
parameters.put("format", "pdf");
parameters.put("WEBDIR", getServletContext().getRealPath("/"));
parameters.put("REPORT_LOCALE", new Locale("ar"));
Connection conn = null;
InputStream is = null;
try
{
conn = getConnection();
is = getServletContext().getResourceAsStream("/WEB-INF/reports/"+reportName+".jrxml");
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename="+reportName+".pdf");
JasperDesign jasperDesign = JRXmlLoader.load(is);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
JasperViewer.viewReport(jasperPrint,false);
conn.close();
}
catch (Exception e) {
e.printStackTrace();
} finally {
closeConnection(conn);
try {
if(is !=null){
is.close();
}
} catch (Exception localException1)
{
}
}
}
protected static void closeConnection(Connection conn) {
try {
if(conn !=null){
conn.close();
}
} catch (Exception ex) {
// System.out.println("Developer Msg : Exception in printReport1Servlet.closeConnection()");
}
}
}