链接到 Web 应用程序中的本地内容
我正在开发旧应用程序的替换应用程序。由于旧应用程序的某些设计限制,“附件”作为字符串路径存储在我们的数据库中(通常文件存储在 Windows 共享驱动器上)。然后,旧应用程序可以通过打开 Windows 命令 shell 并执行给定路径来“打开”附件。
遗留(Oracle Forms)应用程序正在被基于 JSF 的 J2EE Web 应用程序淘汰。新应用程序需要能够以某种方式“打开”或链接到这些旧附件。这可能吗?我尝试使用 file:// URL,但使用它们有很多注意事项。它们仅适用于 IE、firefox/chrome(以及我认为的其他现代浏览器)中的远程主机,阻止本地文件 URL。
对于这个特定的功能来说,只在 IE 上工作是可以接受的。我进一步遇到了带有空格的文件路径的问题。由于某种原因,如果 IE 遇到包含空格的文件路径,则表示
C:\Documents and Settings\user123\My Documents\testing\someFile.txt
它拒绝打开该链接。浏览器会自动将空格 (' ') 替换为其 URL 编码的“%20”。
我正在尝试的关联链接看起来像:
<a href="file:///C:\Documents and Settings\user123\My Documents\testing\someFile.txt">link</a>
我缺少一些简单的东西吗?或者有没有更简单的方法来做到这一点?
我不太确定该标记什么,因此请根据需要随意重新标记。
I am working on a replacement application to a legacy application. Due to certain design limitations of the legacy application, 'attachments' are stored as a String path in our database (generally files stored on a windows shared drive). The legacy application can then 'open' the attachments by opening a windows command shell and executing the given path.
The legacy (Oracle Forms) application is being phased out by a JSF based J2EE web application. The new application needs to be able to 'open' or link to these legacy attachments somehow. Is this even possible? I have attempted to use file:// URLs, but there are lot of caveats with using them. They only work on remote hosts in IE, firefox/chrome (and other modern browser I assume) prevent local file URLs.
Working only on IE is something that can be lived with for this particular feature. I further ran into an issue with file paths with spaces. For some reason if IE encounters a filepath with spaces in it, say
C:\Documents and Settings\user123\My Documents\testing\someFile.txt
it refuses to open that link. The browser automatically replaces the spaces (' ') with its URL Encoded '%20'.
The associated link I am attempting looks like:
<a href="file:///C:\Documents and Settings\user123\My Documents\testing\someFile.txt">link</a>
Is there something simple to this I am missing? Or is there any easier way of doing this?
I wasn't quite sure what to tag this as so feel free to retag as necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过一些广泛的测试,我得出以下结论:
希望这可以帮助其他正在查找文件 URL 信息的人。
After some extensive testing I have reached the following conclusions:
Hopefully this helps someone else out who's looking for information on file urls.
如果您在文件路径周围使用双引号 (
"
)(您可能需要将它们进行 URL 编码为%22
),Windows 将可以使用完整路径:If you use double quotes (
"
) around the path to the file (you will probably need to URL encode these as%22
), windows will be OK with the full path: