This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes opining pdf file using servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "opining pdf file using servlets" Watch "opining pdf file using servlets" New topic
Author

opining pdf file using servlets

Ahmed M. Omar
Ranch Hand

Joined: Mar 02, 2010
Posts: 43
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
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

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!


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: opining pdf file using servlets
 
Similar Threads
Right usage of static modifier ?
Object casting
input to ireport
iReport in Struts action
Problem in opening PDF file in client browser