pdf在iframe中在tomcat上的jsp中,还有Struts2
我在将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这基本上意味着 URL 错误或资源实际上不存在。
要排除第一个,请首先使用绝对 URL 进行测试,从而包括协议和域名,例如
http://example.com/file.pdf
。如果有效,则相对 URL 可能是错误的。任何相对 iframe URL 实际上都是相对于父页面的 URL。如果您知道磁盘文件系统路径如何组合在一起,那么计算正确的相对 URL 应该是显而易见的。要排除第二个,请检查本地磁盘文件系统。如果它不存在,那么您就知道了。但如果它在那里,那么该文件可能是新写入磁盘的并且尚未关闭。如果您使用 Java IO 将此文件写入磁盘,则需要确保关闭该文件上的
OutputStream
。使用以下习惯用法:另请参阅 Sun Java IO 教程。
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:Also see the Sun Java IO tutorial.
我不用Tomcat,但最有可能的是相对路径不正确。
I don't use Tomcat, but the most likely thing is that the relative path is incorrect.
我不知道 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.
.
嗯,你们都说对了一部分,但真正的答案是... 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!