public class JasperPrintServlet
extends HttpServlet {
static Log log = LogFactory.getLog(JasperPrintServlet.class);
public void service(
HttpServletRequest request,
HttpServletResponse response
) throws IOException, ServletException {
ServletContext context = this.getServletConfig().getServletContext();
File reportFile = null;
String fileName = request.getParameter("file_name");
System.out.println();
if (fileName != null)
reportFile = new File(context.getRealPath("/monapp/report/" + fileName+
".jasper"));
else
throw new ServletException("无效的文件名 :" + fileName);
Map parameters = new HashMap();
if (log.isDebugEnabled())
log.debug("fileName=" + fileName) ;// " reportId=" + reportId);
JasperPrint jasperPrint = null;
Connection conn = null;
JasperReport jasperReport = null;
try {
if (log.isDebugEnabled())
log.debug("reportFile's real path is " + reportFile.getPath());
jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath());
conn = DataBaseConnection.getConnection();
jasperPrint =
JasperFillManager.fillReport(
jasperReport,
parameters,
conn );
System.out.println(jasperPrint+"====");
}
catch (JRException e) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("");
out.println("");
out.println("");
out.println(" <link title="\" href="\" type="\" rel="\" text="">");
out.println("");
out.println("");
out.println(
"Empty response.");
out.println("");
out.println("");
}
}
}
以上是我的sevlet源码,当执行完 jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, conn );时返回null。不知是何原因?(其中 jasperReport, parameters, conn 裙可以在调试状态中看到值)