pdf在iframe中在tomcat上的jsp中,还有Struts2

发布于 2024-08-14 11:53:39 字数 397 浏览 4 评论 0原文

我在将 pdf 文件显示在 jsp 页面中时遇到一些问题。我将 pdf 保存在我的 tomcat 服务器上,文件位置如下 c:/tomcat 6.0/webapps/appname/reports/saved/filename.pdf 我正在尝试打开该文件(最好不使用 c: 位置)并使用以下标记将其显示在我的 jsp 文件中的 iframe 中...

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

我稍后会担心大小调整问题:)

但我明白了所请求的资源不可用。

我很确定这是我没有看到的愚蠢的事情,我真的很感激我能得到的任何帮助。

谢谢,

阴影

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

↘紸啶 2024-08-21 11:53:40

请求的资源不可用

这基本上意味着 URL 错误或资源实际上不存在。

要排除第一个,请首先使用绝对 URL 进行测试,从而包括协议和域名,例如http://example.com/file.pdf。如果有效,则相对 URL 可能是错误的。任何相对 iframe URL 实际上都是相对于父页面的 URL。如果您知道磁盘文件系统路径如何组合在一起,那么计算正确的相对 URL 应该是显而易见的。

要排除第二个,请检查本地磁盘文件系统。如果它不存在,那么您就知道了。但如果它在那里,那么该文件可能是新写入磁盘的并且尚未关闭。如果您使用 Java IO 将此文件写入磁盘,则需要确保关闭该文件上的 OutputStream。使用以下习惯用法:

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) {}
}

另请参阅 Sun Java IO 教程

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.

小清晰的声音 2024-08-21 11:53:40

我不用Tomcat,但最有可能的是相对路径不正确。

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

烈酒灼喉 2024-08-21 11:53:40

我不知道 Tomcat,但你弄乱了路径。如果 PDF 位于 c:\tomcat 6.0\webapps\appname\index.html 中,则使用 ./reports/saved/filename.pdf。

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

殊姿 2024-08-21 11:53:40

嗯,你们都说对了一部分,但真正的答案是... URL 文件夹区分大小写... 我限制了文件夹名称,并且找到了资源!

感谢您的帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文