Hi,
I have a J2ee application, in which on the click of a link, a pdf file needs to be generated and displayed on a new tab or window.
Currently, the pdf is generated, but, when written to the output stream, and redirected to the view, the screen just hangs.. I assume there is an exception of some sort which is not being logged for some reason.
I am not sure how to go about debugging this..
Any help is appreciated,
TIA
Aneesh Vijendran
Ranch Hand
Joined: Jun 29, 2008
Posts: 125
posted
0
Without even giving a code snippet, it's tough to debug. It could be, if you are reading to a byte array, the byte array might have been initilized to accomodate more memory.
Try debugging your code in eclipse using breakpoints. You can run your tomcat inside or outside eclipse and then debug.
Add try{}catch to the top method and log the exception information.
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 368
posted
0
vinitha simon wrote:Hi,
I have a J2ee application, in which on the click of a link, a pdf file needs to be generated and displayed on a new tab or window.
Currently, the pdf is generated, but, when written to the output stream, and redirected to the view, the screen just hangs.. I assume there is an exception of some sort which is not being logged for some reason.
I am not sure how to go about debugging this..
Any help is appreciated,
TIA
Did you set the MIME type correctly? Something like 'application/pdf'
Additionally you can try clearing you browser cache and also redeploy the webapp on the server after cleanly undeploying the app from the server(like removing the web app's folder from work directory in tomcat)
Thanks and Regards
amarshi mohanty
Ranch Hand
Joined: Jul 01, 2008
Posts: 110
posted
0
Hope this will help you..
Document document = new Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
document.setPageCount(1);
document.open();
document.add(Add Your Object);
document.close();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
response.setContentLength(baos.size());
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
Thanks
Amarshi
SCJP (97%), SCWCD (95%))
vinitha simon
Ranch Hand
Joined: Dec 13, 2007
Posts: 64
posted
0
I think the pdf file is not being generated correctly, I did verify the mimetype as well.
But, the java code does not throw any exceptions. Is that normal?
Yes, it's quite normal for Java code to not throw exceptions. It's still possible that your code has bugs, though, even if it doesn't throw an exception. In fact I would guess it's quite likely, since it isn't doing what you want it to do. That's the definition of "bug".
vinitha simon
Ranch Hand
Joined: Dec 13, 2007
Posts: 64
posted
0
Thanks everyone for the help, I think I'm just going to rewrite my code and try to get it working.