aspose file tools*
The moose likes JSP and the fly likes Using JSP for PDF output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Using JSP for PDF output" Watch "Using JSP for PDF output" New topic
Author

Using JSP for PDF output

M.C. Horn
Greenhorn

Joined: Sep 18, 2002
Posts: 28
Maybe someone out there has done this successfully, or knows the pitfalls. I would like to use a JSP response in the following manner:
byte[] pdfBytes = report.pdfBytes();
// send the pdf bytes to the response
response.setContentType("application/pdf");
response.setContentLength(pdfBytes.length);
ServletOutputStream out = response.getOutputStream();
out.write(pdfBytes);
out.close();
The intent here is to use a JSP in place of a Servlet to write pdf reports. I haven't tried it yet, but have a feeling there is something wrong with my approach. Thanks ahead of time !
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
Three thoughts:
  • The variable "out" is already bound (as type JspWriter).
  • If there are any characters (even whitespace) outside your one big <% ... %> that encloses your example, the system will try to output them, and you will get an exception re the response already being committed.
  • It is a bad idea, even if you could make it work. JSP is for mixing static character data with some dynamically-generated content. Preferably when the scriptlets are a very small percentage of the whole page. You only have dynamic content. Use a servlet!

  • Cheers-
    - Marty


    Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Using JSP for PDF output
     
    Similar Threads
    Jasper report - Change Page Orientation
    PDF file read streaming
    How jsp and a pdf document displayed in the same browser?
    Javascript alert from PDF in JSP file
    PDF file read