Jump to content
Changes to the Jaspersoft community edition download ×

problem displaying pdf: Cannot set header


Recommended Posts

By: Outey Ky - chhunak

problem displaying pdf: Cannot set header

2002-10-29 08:43

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...

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...