Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

opining pdf file using servlets

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to opining pdf files in servlet application this the code




when i runing this code the pdf file works randomly (ie:works fine for 3 times and appears corrupted 2 times)


how can i write more professional code to make the pdf file works correctly every time
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you get a "corrupted" pdf, what do you get? A zero-byte file, or garbage?

One possibility I see, if something goes wrong with the database, your servlet may produce no output. Any exceptions that occur prior to your out.write(...) call in the "try" block will cause that out.write(...) call to never happen.

A better solution may be to create an empty buffer before the "try" block, write to that empty buffer within the "try", and then in the "finally", write that buffer to "out". The other advantage to this is that you should also be able to create & send the "Content-Length" header, which can help the Acrobat Reader plugin know how much data it should expect.

Good luck!
 
I once met a man from Nantucket. He had a tiny ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic