|
|
Cannot forward after response has been committed? PDF save in Browser?
.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)at org.apache.tomcat.util.net.MasterSlaveWorkerThread .run(MasterSlaveWorkerThread.java:112)at java.lang.Thread.run(Thread.java:619)
My code for the generate and forward of the pdf follows here:
quote: public class MakePDF extends AbstractPdfView{
@Override protected void buildPdfDocument(Map model, Document document, PdfWriter writer, fromServletRequest request, fromServletResponse response) throws Exception {
String linebreak = new String(quot;\nquot;); Examination_data examination_data = null; Patient_data patient_data = null;
String filename;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
patient_data = (Patient_data) model.get(quot;patient_dataquot;); examination_data = (Examination_data) model.get(quot;examination_dataquot;);
PdfWriter.getInstance(document, baos);
response.setContentType(quot;application/pdfquot;);
filename = (String) examination_data.getFilename();
String split[] = filename.split(quot;\\.quot;);
if (split.length == 1){ filename = filename + quot;.pdfquot;; } else if (split.length == 2){
if (!split[1].equals(quot;pdfquot;)){ split[1] = quot;.pdfquot;; filename = split[0] + split[1]; }
}
response.setHeader( quot;Content-dispositionquot;, quot;attachment; filename=quot; + filename + quot;quot;);
document.open();;
/** * In das PDF Dokument einfuegen */ // Name document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Name: quot;)); document.add(new Paragraph(patient_data.getName()));
// Firstname document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Firstname: quot;)); document.add(new Paragraph(patient_data.getFirstname()));
// Date of Birth document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Date of birth: quot;)); document.add(new Paragraph(quot;testquot;));
// Gender document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Gender: quot;)); document.add(new Paragraph(patient_data.getGender()));
// Bodysize document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Bodysize: quot;)); document.add(new Paragraph(patient_data.getBodysize()));
// Weight document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Weight: quot;)); document.add(new Paragraph(patient_data.getWeight())); document.add(new Paragraph(linebreak));
// Indication document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Indication:quot;)); document.add(new Paragraph(linebreak)); document.add(new Paragraph(examination_data.getIndication()));
document.add(new Paragraph(linebreak)); document.add(new Paragraph(linebreak));
// Finding document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Finding:quot;)); document.add(new Paragraph(linebreak)); document.add(new Paragraph(examination_data.getFinding()));
document.add(new Paragraph(linebreak)); document.add(new Paragraph(linebreak));
// Comment document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Comment:quot;)); document.add(new Paragraph(linebreak)); document.add(new Paragraph(examination_data.getComment()));
document.add(new Paragraph(linebreak)); document.add(new Paragraph(linebreak));
//Diagnosis document.add(new Paragraph(linebreak)); document.add(new Paragraph(quot;Diagnosis:quot;)); document.add(new Paragraph(linebreak)); document.add(new Paragraph(examination_data.getDiagnostics()));
document.close();
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
}
}
Does anybody have an advice or knows a workaround for this error?
Thanks
Tim
It's not obvious what the actual reason is. But since you already send the response to the client nothing else is allowed to do something like this anymore. The forward mentioned in the error message - however it is triggered - is quot;something like thisquot;. It might be an Acegi issue. Does it cause the forward for a security issue?
Joerg
Is this application using JSF? If a Faces Request is being made which generates a Non-Faces Response, then you will need to skip the Faces Response by calling FacesContext.responseComplete().
Hi cmelger,
thanks for your post, it helps me a lot.
Thank you
Tim |
|