Meaningless Drivel is fun!*
The moose likes Struts and the fly likes struts2 jasperreports showing garbage in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 jasperreports showing garbage in browser" Watch "struts2 jasperreports showing garbage in browser" New topic
Author

struts2 jasperreports showing garbage in browser

Mick Smith
Greenhorn

Joined: Dec 10, 2009
Posts: 14
Hi

I am trying to implement the struts2 jasperreports tutorial as listed at: http://struts.apache.org/2.0.14/docs/jasperreports-tutorial.html

When my action executes, the resulting page I get taken to displays the following jargon:

%PDF-1.4 %��3 0 obj <>stream x���]O�0��8���nw3����/�� U���a.�[���i�F��,-<�ěvV �����\ ��}m�n��{!o��[�r��M�,W�Y�d�����O���V�K'k��q�s�#� =���%Ś��&�����ɣ2#�����x���B��U7� �K�n,VL�L�,�eѥSQ��>��O0��/�?�endstream endobj 1 0 obj <>/Parent 4 0 R/Contents 3 0 R/Type/Page/Resources<>/Font<>>>/MediaBox[0 0 595 842]>> endobj 5 0 obj [1 0 R/XYZ 0 854 0] endobj 2 0 obj <> endobj 4 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <>/Pages 4 0 R>> endobj 9 0 obj <> endobj xref 0 10 0000000000 65535 f 0000000352 00000 n 0000000621 00000 n 0000000015 00000 n 0000000709 00000 n 0000000586 00000 n 0000000772 00000 n 0000000826 00000 n 0000000858 00000 n 0000000961 00000 n trailer <]/Info 9 0 R/Size 10>> startxref 1110 %%EOF

The tutorial doesn't mention anything about setting content type or anything else (I presume the plugin will do all that automatically or maybe I am wrong). I have implemented exactly as per that tutorial.

Anyone with any idea as to what is happening or what needs to be done so that I can display the pdf in the browser or even get a link to the pdf on screen? I have searched the web and this forum but cant get anything specific with the struts2 jasperreport plugin.

1 point of note, I had problems in retrieving my .jrxml file when trying to compile into a jasper file. However, I do have a jasper file now and I presume it is compiled correctly.
My conosole outputs the following which makes me believe that my jasper file is compiled fine.



thanks for any assistance
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd check your browser's PDF settings first; normally it'll either display inline or ask you to download.
Mick Smith
Greenhorn

Joined: Dec 10, 2009
Posts: 14
Hi David

I am able to view pdf documents in both IE & Firefox when coming across all pdf documents accross the Internet.

My firefox settings for all adobe acrobat documents was to display in firefox(I presume this is inlne). I since modified it to use Adobe Read however my problem before still persists when I try to use my struts2 action to display the pdf document.

Do you have any other suggestion I can try to solve this problem? As mentioned before my code is very simlar to that of the tutorial.

thanks for your assistance

Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
David Newton wrote:I'd check your browser's PDF settings first; normally it'll either display inline or ask you to download.

This assumes the server sends the correct content type header.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It does.

Without the actual code and/or configuration, it's impossible to help. We have several apps in production that use the JR plugin without incident (and without changing browser settings), so I'm not sure what else to suggest. Is the format result attribute being set?
Mick Smith
Greenhorn

Joined: Dec 10, 2009
Posts: 14
I found Bruce Phillips jasper struts tutorial at http://www.brucephillips.name/blog/print.cfm?id=1A8B29F1-3048-7B4D-A9962A2D974F0DED

I downloaded his war, deployed it in eclipse and it works fine. Pdf comes up no problem. That war uses struts2-jasperreports-plugin-2.0.11.1

I then copied over his class files, jasper files, etc over to my project which uses struts2-jasperreports-plugin-2.1.8 but I get the same problem as before!
I wonder Im i missing a jar or something else in my project.

I have the following jar files:
struts2-jasperreports-plugin-2.1.8.jar
jasperreports-3.7.1.jar
iText-2.1.7.jar
jdt-compiler-3.1.1.jar

Im stumped as to why its not working!
Mick Smith
Greenhorn

Joined: Dec 10, 2009
Posts: 14
Just an update.. I did another test whereby I put my action class & other necessary code into the Bruce Phillips war, deployed it, tested it & it worked fine. the pdf is rendered and displayed ok.

This means that my code is ok, my compiled jasper file is ok. This leaves me thinking that I am defintely missing something when using struts2-jasperreports-plugin-2.1.8.jar.
Does anyone know what are the dependant jars & versions needed for struts 2.1.8 when trying to run struts2-jasperreports-plugin-2.1.8.jar?

I originally usedthis list as my base(http://struts.apache.org/2.x/docs/jasperreports-tutorial.html) but I must be missing some correct version or something!:

dist/jasperreports-X.jar
lib/commons-*.jar (all the commons - except maybe for commons-logging)
lib/itext-X.jar
lib/jdt-compiler.jar
Copy these jars over to your S2_WEBAPP/WEB-INF/lib directory, and add them to your classpath.

thank again
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://mvnrepository.com/artifact/org.apache.struts/struts2-jasperreports-plugin/2.1.8
http://mvnrepository.com/artifact/jasperreports/jasperreports/3.1.2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 jasperreports showing garbage in browser