By: Outey Ky - chhunak
problem displaying pdf: Cannot set header
2002-10-29 08:44
Hi,
I am encountering the following problem when I am trying to generate the pdf output of the JasperReports. I am using Websphere 3.5.3 and the server output the following message:
ERROR: Cannot set header. Response already committed.
Here is my servlet code. (My jsp page that I am targetting only contain javascripts, html, and a few scriptlet.)
public void doDisplayTestReport(HttpServletRequest request, HttpTaskTarget target)
throws javax.servlet.ServletException, java.io.IOException {
HttpServletResponse resp = target.getHttpServletResponse();
//check to verify if connection is still active
if (getUser(request) == null) {
goRoot(request, target.getHttpServletResponse());
return;
}
java.sql.Connection connection = null;
ServletContext context = this.getServletConfig().getServletContext();
try {
connection = getConnection(request, target);
//********************************************************
File reportFile = new File(context.getRealPath("/reports/mydoc.jasper"));
Map parameters = new HashMap();
parameters.put("ReportTitle","The Test JasperReport");
parameters.put("BaseDir", reportFile.getParentFile());
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,connection);
if (bytes !=null && bytes.length > 0) {
resp.setContentType("application/pdf");
//resp.setHeader("Cache-Control", "no-cache"); I try this.
resp.setContentLength(bytes.length);
ServletOutputStream outputStream = resp.getOutputStream();
outputStream.write(bytes, 0, bytes.length);
outputStream.flush();
outputStream.close();
}
else {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>JasperReports - Test Sample Report</title>");
out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<span class=\"bold\">Empty response.</span>");
out.println("</body>");
out.println("</html>");
System.out.println("There have been an error in creating the report.");
}
//********************************************************
//target view jsp page
stockMenuAdmin(connection, request);
target.setName("view_DisplayTestReport");
return;
} catch (Exception e) {
goBack(
request,
target.getHttpServletResponse(),
getError(request, "19", "Error", e));
return;
} finally {
releaseConnection(connection);
}
}
Any help is greatly appreciated...
problem displaying pdf: Cannot set header
2002-10-29 08:44
Hi,
I am encountering the following problem when I am trying to generate the pdf output of the JasperReports. I am using Websphere 3.5.3 and the server output the following message:
ERROR: Cannot set header. Response already committed.
Here is my servlet code. (My jsp page that I am targetting only contain javascripts, html, and a few scriptlet.)
public void doDisplayTestReport(HttpServletRequest request, HttpTaskTarget target)
throws javax.servlet.ServletException, java.io.IOException {
HttpServletResponse resp = target.getHttpServletResponse();
//check to verify if connection is still active
if (getUser(request) == null) {
goRoot(request, target.getHttpServletResponse());
return;
}
java.sql.Connection connection = null;
ServletContext context = this.getServletConfig().getServletContext();
try {
connection = getConnection(request, target);
//********************************************************
File reportFile = new File(context.getRealPath("/reports/mydoc.jasper"));
Map parameters = new HashMap();
parameters.put("ReportTitle","The Test JasperReport");
parameters.put("BaseDir", reportFile.getParentFile());
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,connection);
if (bytes !=null && bytes.length > 0) {
resp.setContentType("application/pdf");
//resp.setHeader("Cache-Control", "no-cache"); I try this.
resp.setContentLength(bytes.length);
ServletOutputStream outputStream = resp.getOutputStream();
outputStream.write(bytes, 0, bytes.length);
outputStream.flush();
outputStream.close();
}
else {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>JasperReports - Test Sample Report</title>");
out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<span class=\"bold\">Empty response.</span>");
out.println("</body>");
out.println("</html>");
System.out.println("There have been an error in creating the report.");
}
//********************************************************
//target view jsp page
stockMenuAdmin(connection, request);
target.setName("view_DisplayTestReport");
return;
} catch (Exception e) {
goBack(
request,
target.getHttpServletResponse(),
getError(request, "19", "Error", e));
return;
} finally {
releaseConnection(connection);
}
}
Any help is greatly appreciated...
0 Answers:
No answers yet