views:

428

answers:

4

Hello Everyone,

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

+1  A: 

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.

BalusC
I know the file exists, and that the outputsteam is closed since I can open it from the file location. The problem with testing it with the absolute http address is that I can't figure it out. I've tried accessing it through http://localhost:8080/appname/reports/saved/filename.pdf, but I get the same error.
Shaded
Then it is not there where you think it is or there is more at matter. Try to figure what `new File("c:/path/to/file.pdf").exists()` inside a Servlet class says (use absolute disk file system path, not relative path!).
BalusC
A: 

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

me_here
A: 

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. .

raphaelr
You cannot tell that without knowing the parent absolute URL.
BalusC
The parent absolute URL is c:\tomcat 6.0\webapps\appname\pdfViewer.jspSo I've tried src="reports/saved/reportname.pdf" and all possible combinations I could think of, all of which result in "resource is not available"
Shaded
A: 

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!

Shaded