报告.java
byte[] pdfbyte = null;
try {
dbcon connect = new dbcon();
ServletContext context = this.getServletConfig().getServletContext();
String compiledFileName = context.getRealPath("/jasper/report3.jasper");
System.out.print(compiledFileName);
// String var = request.getParameter("var").toString();
//String res = JOptionPane.showInputDialog(null, "What is your name?", "Enter your name",JOptionPane.QUESTION_MESSAGE);
File reportFile = new File(compiledFileName);
HashMap parameters = new HashMap();
// // parameters.put("itemName", var);
parameters.put("ReportTitle", "MyReport");
// parameters.put("BaseDir", reportFile.getParentFile());
// parameters.put("EmpNo", 32504);
JasperPrint jasperPrint = null;
Connection conn = connect.dbstate().getConnection();
try {
try {
jasperPrint = JasperFillManager.fillReport(compiledFileName, parameters, conn);
pdfbyte = JasperExportManager.exportReportToPdf(jasperPrint);
} catch (Exception e) {
System.out.print("E" + e);
}
} catch (Exception ex) {
System.out.println("*** Could not create compiled jasper file: " + ex.getMessage());
} finally {
try {
connect.dbstate().close();
} catch (SQLException ex) {
System.out.println("could not close databse after filling the report ");
}
}
ServletOutputStream outstream = response.getOutputStream();
response.setContentType("application/pdf");
response.setContentLength(pdfbyte.length);
response.setHeader("Content-disposition", "inline; filename=\"Report.pdf\"");
outstream.write(pdfbyte);
} catch (Exception e) {
System.out.print(e);
e.printStackTrace();
}
图书馆
我在 Netbeans 上遇到以下错误
SEVERE: A web application registered the JBDC driver [oracle.jdbc.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Ejava.lang.NullPointerExceptionjava.lang.NullPointerExceptionjava.lang.NullPointerException
at jasper.Report.processRequest(Report.java:63)
at jasper.Report.doGet(Report.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:619)