• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using JSP for PDF output

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    reply
      Bookmark Topic Watch Topic
    • New Topic