Shaded
Shaded

Reputation: 17826

pdf in iframe in jsp on tomcat, also Struts2

I'm having some issues getting my pdf file to display in my jsp page. I have the pdf saved on my tomcat server with a file location as follows c:/tomcat 6.0/webapps/appname/reports/saved/filename.pdf I am trying to open that file (preferably not using the c: location) and displaying it in an iframe in my jsp file using the following tag...

<iframe src="../appname/reports/saved/filename.pdf"></iframe>

I'm going to worry about sizing later :)

but I'm getting that the requested resource is not available.

I'm pretty sure that this is something stupid that I'm just not seeing and I'd really appreciate any help I can get.

Thanks,

Shaded

Upvotes: 0

Views: 2966

Answers (4)

Shaded
Shaded

Reputation: 17826

Well you were all partially right, but the real answer was... the URL folders are case-sensitive... I capped the folder names and the resource was found!

Thanks for the help!

Upvotes: 0

raphaelr
raphaelr

Reputation: 67

I don't know Tomcat, but you messed up the path. If the PDF is located in c:\tomcat 6.0\webapps\appname\index.html, then use ./reports/saved/filename.pdf. .

Upvotes: 0

me_here
me_here

Reputation:

I don't use Tomcat, but the most likely thing is that the relative path is incorrect.

Upvotes: 0

BalusC
BalusC

Reputation: 1108632

requested resource is not available

This basically means that either the URL is wrong or that the resource actually isn't there.

To exclude the first, test it with an absolute URL first, thus including the protocol and the domain name, e.g. http://example.com/file.pdf. If it works, then the relative URL is likely wrong. Any relative iframe URL is actually relative to the URL of the parent page. If you know how disk file system paths fits together, then figuring the right relative URL should be obvious enough.

To exclude the second, check the local disk file system. If it is not there, then you know enough. But if it is there, then the file maybe is freshly new written to disk and not closed yet. If you're writing this file to disk using Java IO, then you need to ensure that you close the OutputStream on that. Use the following idiom:

OutputStream output = null;
try {
    output = new FileOutputStream(new File("c:/path/to/file.pdf"));
    // write ..
} finally {
    if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
}

Also see the Sun Java IO tutorial.

Upvotes: 1

Related Questions