Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems displaying a pdf file in a JSP page

 
Andres Delrotti
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
^^
So what alternative approach would you recommend?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!