• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Problems displaying a pdf file in a JSP page

 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyon!? Hows it going?

I have a problem. See javascript below.

function opens(){
var frame = document.getElementById("frame");
var frame1 = document.getElementById("divFrame");
frame1.style.display = "block";
frame.src="file:///C:\\somepdffile.pdf";

}


The javascript code above works perfectly well in written and done in a static html page. It does not work on a jsp page. The content of the pdf file would not display. We already tried a lot of combinations on the frame.src url but it still wont work. Can anyone help me on this? Is this caused by browser or security issues? Any form of help would be appreciated. Thanks.
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A page originating from a web server can't open a local file. Browsers will do that if the HTML page is opened locally, but not if it is sent from a server. It would be a huge security hole if that were possible.
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
^^
So what alternative approach would you recommend?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Andres Delrotti:
^^
So what alternative approach would you recommend?



What are you trying to accomplish?
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
^^
Just to display the content of the pdf file located in a folder in the server.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the PDF is located within the directory structure of your webapp and not under WEB-INF, you can simply link to it like any other page or image.
If it's under WEB-INF, you can forward to it with a requestDispatcher.
If it's not located within your app's directory structure, you'll need to write a servlet that streams it to the user's browser.

If you're still stuck after this, let us know where you're storing your PDFs.
 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:

If it's not located within your app's directory structure, you'll need to write a servlet that streams it to the user's browser.

If you're still stuck after this, let us know where you're storing your PDFs.



The pdf file is located in a folder in the server. A folder different from where the application is deployed. It's not within our app's directory structure.

How exactly do I write a servlet that streams it to the user's browser? Sorry I don't have any idea on it. Never did it before. I have used servlets before but I haven't done that "streaming to the user's browser" thing yet.
 
I'm doing laundry! Look how clean this tiny ad is:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic