• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display PDF in JSP Page Using Servlet

 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a jsp page with two containers. the left is a dynatree which lists drawing numbers. In the right container I want to display the drawing as a pdf file.

Here is the servlet where the PDF file is read into response.



Now can someone help me to know what code to put in the container to post to servlet an display response?
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to have a form with a button, and on click of the button you need to call this servlet.

 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surendra Kumar wrote:You need to have a form with a button, and on click of the button you need to call this servlet.



I found that the object tag with data set to servlet name will work.

Is this an acceptable method?
 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hold on a minute. The object tag works great with IE10 but when ran on IE9 or IE8 all I get is the red X where the PDF file should be displaying.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surendra Kumar wrote:You need to have a form with a button, and on click of the button you need to call this servlet.

No form is required. Why should there need to be a form?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your data param a full server-relative URL? Have you used the browser tools to see what response the request for the PDF is returning?
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Surendra Kumar wrote:You need to have a form with a button, and on click of the button you need to call this servlet.

No form is required. Why should there need to be a form?


That's just one way to do it. Another way might be an AJAX request to make servlet call when the data on the first container is complete or something like that.
That's what I could understand from the question.
Not sure of more ways to achieve it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajax isn't needed either. I'm not sure why you think an extraneous submission is needed. He wants to display the PDF on-page, not after some user action like clicking a submit button.
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, got it. He wants to show PDF on page load itself.
Thanks.
 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Ajax isn't needed either. I'm not sure why you think an extraneous submission is needed. He wants to display the PDF on-page, not after some user action like clicking a submit button.


I have done some more testing and it appears that if compatibility mode is turned on it fails. When turned off it works okay just all the other app are not displayed correctly. Is there a was to do the compatibility setting to turn off within the application?
 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it works okay in IE9 with compatibility turned off but still fails in IE8. Where the pdf file should appear I get a red X.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, IE8 is so out of date, I wouldn't worry about it.

One of the only reasons to support such an antiquated browser as IE8 today is for customers who are still stuck on XP and cannot upgrade past IE8. As of April of this year, Microsoft is dropping support for XP, and at that point there will be no reason to support IE8 at all.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. you might try using an iframe to display the PDF.
 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:P.S. you might try using an iframe to display the PDF.


Should I try the set it up where it determines which browser version and when IE8 use the iframe and all others use object?

If so should I detect browser at page level or app level?
 
Sean Rowlandson
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definitely detect the browser type at page level, unless you actually have other browser specific functionality?
 
Steve Dyke
Ranch Hand
Posts: 1706
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sean Rowlandson wrote:Definitely detect the browser type at page level, unless you actually have other browser specific functionality?


Thanks, that's the direction I will go.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic