• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Opening pdf file using jsp

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem that im facing is, the below code is working correctly and retrieve the pdf format files correctly and displaying it in the iframe. but it is only working in eclipse internal browser but not in firefox or internet explorer. what will be the reason for this....

Source code:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Browse File</title>
</head>
<body>
<center><h3>File Uploading</h3></center>
<center>
<form name="PDFForm" action="browse.jsp" method="post">
Select PDF : <input type="file" name="txtPDFFile" value="">
<input type="submit" value="View">
</form>
<% String s=request.getParameter("txtPDFFile");
if(s!=null){
%>
<iframe src ="<%= s %>" width="100%" height="700">
<p>Your have to select file to view.</p>
</iframe>
<% } %>
</center>
</body>
</html>
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest you view source on the generated html to see what the src link looks like in the different browsers.
Look at that url to determine whether you think it should work or not.

All you seem to be doing is putting the filename straight into the iframe.
If it works in the Eclipse internal browser, then that will be the exception, and not the norm.

The input type="file" control is intended for uploading files to the server. Not opening local files for viewing in the browser.

 
Ganesh Ravi Kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Internet Explorer im getting the fully qualified path. Eg: D:\Ganesh\Assign1.pdf. But it only displays the iframe as blank.......it is not displaying the pdf file. But when working with FireFox im getting only the resource name. Eg: Assign1.pdf. thats it. And i have concatenated the resources name with the fully qualified path (Eg: D:\Ganesh\Assign1.pdf) when using firefox and it is returning a alert message like........... "Firefox doesn't know how to open this address, because the protocol (d) isn't associated with any program". And one more thing as you said, input type file only used for browsing.....yes that i know......im passing the path to the iframe with the use of input type submit.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

And one more thing as you said, input type file only used for browsing



No, I did not say that.
I said that the input type='file' is intended for uploading files to the server.

You seem to be attempting to use it another fashion - choosing a file to display in your browser window/iframe.
This is not a supported operation.

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Ravi Kumar wrote:im passing the path to the iframe with the use of input type submit.



Let's go back a step. What exactly are you trying to do here? Upload a file from the client to your server? Display in the browser a file which is downloaded from your server? Display in the browser a file which already exists on the client machine? Something else?
 
Ganesh Ravi Kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
exactly........you are right......(Something else?)no more............what i have to do for that..........u have understood clearly about my problem........solution for that???
 
Ganesh Ravi Kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
somebody fix this issue............how to display pdf file using jsp in different browser............
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ganesh Ravi Kumar wrote:You have understood clearly about my problem.


Actually, Paul had not - which is why he asked what exactly you're trying to do. Notice how he suggests at least 3 different things you may be trying to do? Unless you tell us which it is, there's not much we can do to help.
 
Ganesh Ravi Kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im not trying to do three different things.......i just want to display the pdf file in the browser......thats it.......the code that i posted have some logic, im asking why it is not working in mozhilla and ie.......whether i have made any modifications in that code...........
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to src of the frame to be a file from the local file system you'll need to use the file:/// protocol in front of your src url if you're going to use an absolute URL like that.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really want to serve from the file system? You do realize that that means that it will work on your browser an no one else's, right?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's certainly some evidence here that Ganesh doesn't realize that the JSP runs on the server and generates HTML which is executed in the browser. That being the case, the scriptlet in the JSP is useless. There's also the possibility that Ganesh doesn't realize that the browser doesn't have direct access to the file system on the server, which ties in to the first possible misunderstanding.

However all we have is an incomplete and incoherent description of the requirements. We don't know whether these PDF files to be displayed in the browser are coming from the client machine or from the server, for a start.

Using a browser to display files from the client machine is impractical and pointless and probably not allowed because of security issues, besides which the browser has no way of identifying files on the client anyway. But that still might be the requirement if it's coming from somebody who doesn't understand the web environment.

On the other hand if the requirement is to display files which come from the server, then what's required is a file download. A JSP is completely the wrong tool to download binary files, what is required is a download servlet.

On the other other hand, there's also the fact that Ganesh has included HTML code which is designed to upload files to the server, which you wouldn't do by accident if you were a beginner. And he mentions another FAQ, which is that IE uploads the whole file path when you do that and other browsers don't. This almost looks like he wants to upload a file path and not to upload the contents of the file, which would be a different misunderstanding. It rather looks like he is trying to upload the path to a file on the client and then generate HTML to display that file in the browser, which would be pretty useless even if it could be done, which it can't. Anyway there's plenty of scope for guessing about what the real requirements are.

So hopefully Ganesh can take this post and take it to whoever the real requirement came from. Perhaps that person could pick out whatever applies to that requirement and clarify things.
 
Alex Hurtt
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well he said he wanted to display a pdf in a browser. What he's doing can work...doesn't matter if it's a jsp generating the HTML or it's a static HTML page. He just has the content of the src attribute wrong. Whether he's trying to display the pdf from the server or really off the local file system...either way he's got the src attribute content wrong. I think he's maybe lacking some foundational understanding about what code gets interpreted/executed where and how the browser resolves resources.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic