Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

pdf in browser  RSS feed

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.
.
.

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/MyServletPDF?username=TEST");
response.setContentType("application/pdf");
dispatcher.include(request,response);
%>

While debugging everything is going through... even it passes through the last line. But the pdf is not launching... showing only a blank screen in its status bar as "Connecting"... Earlier it was launching.. but suddenly this issue is raising up. Is there any IE settings need to be checked? Please help me. I'm totally struck up.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%>

If this means that you're doing this in a JSP - don't, you will likely not succeed. Binary content needs to be handled in a servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to find out why.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All pdf formation it in servlet .. here in jsp i'm only displaying in the browser. It was working till yesterday. Suddenly facing this issue. Not did any changes in code though.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All pdf formation it in servlet .. here in jsp i'm only displaying in the browser.

Use a servlet to stream it to the browser instead.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the article -- it will tell you how JSP adds extra characters that can "pollute" a binary stream.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
All pdf formation it in servlet .. here in jsp i'm only displaying in the browser.

Use a servlet to stream it to the browser instead.


I tired stream from servlet to the browser. still the same problem exists. Is there any browser setting issue will be there?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post the server-side code you're using for streaming from a servlet. What the browser will do with the PDF is up to the browser - it might display it, it might save it, or it might ask what to do with it.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is problem in the code, as it is working in other client machines. Its not working only in a particular m/c.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neeba Rebbaca wrote:I don't think there is problem in the code, as it is working in other client machines. Its not working only in a particular m/c.


That's because, as has been said, you have no control what happens to files if you stream them to a client from a servlet. The client machine might not have a PDF viewer application at all or the browser might have been setup so as not to launch other applications. You might even observe different behavior on different browsers on the same computer. The best you can do from the server side is set the right headers. What the client will do with those headers is anyone's guess.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
he client machine might not have a PDF viewer application at all or the browser might have been setup so as not to launch other applications.


Installed adobe pdf and other applications also launching.
The best you can do from the server side is set the right headers


What is the server side headers to be set?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read up on the Content-Disposition HTTP header.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I launch the pdf from servlet inside the server, in browser it is showing as "Internet Explorer cannot display the webpage". The same code is working in other places.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this may be be due to IE not using plugins to display embedded content; there was a lawsuit some years ago that prevents Microsoft from doing this. Or it could just be IE not behaving correctly; it has a long tradition of that :-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!