链接到 Web 应用程序中的本地内容

发布于 2024-10-18 10:15:12 字数 772 浏览 1 评论 0原文

我正在开发旧应用程序的替换应用程序。由于旧应用程序的某些设计限制,“附件”作为字符串路径存储在我们的数据库中(通常文件存储在 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 技术交流群。

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

发布评论

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

评论(2

演出会有结束 2024-10-25 10:15:12

经过一些广泛的测试,我得出以下结论:

  • 只有 IE 会打开远程主机页面上的 file:// 链接,其他浏览器会完全阻止它们,并且当用户单击它们时不会发生任何情况。
  • IE 将仅打开指向驻留在网络驱动器上的文件的 file:// URL
    • 如果用户点击指向用户本地驱动器上的文件的 file:// 链接,则不会发生任何事情,也不会出现错误。
  • 如果用户单击指向网络文件的 file:// 链接,则该文件将在浏览器中打开(如果可能)。
  • 如果 file:// url 指向无效位置(未映射的网络驱动器、网络驱动器上不存在的文件),Windows 将显示弹出错误。
  • 文件路径中的空格需要使用 %20 进行 URL 编码,

希望这可以帮助其他正在查找文件 URL 信息的人。

After some extensive testing I have reached the following conclusions:

  • Only IE will open file:// links that are on a page from a remote host, Other browsers will block them outright and nothing will happen when a user clicks on them.
  • IE will only open file:// URLs that point to a file that resides on a network drive
    • If a user clicks on a file:// link pointing to a file on the user's local drive, nothing will happen and they will get no error.
  • If a user clicks on a file:// link that points to a network file it will open in the browser, if possible.
  • If the file:// url points to an invalid location (unmapped network drive, file on a network drive that doesn't exist), Windows will show a popup error.
  • Spaces in the file path needs to be URL encoded with %20

Hopefully this helps someone else out who's looking for information on file urls.

韵柒 2024-10-25 10:15:12

如果您在文件路径周围使用双引号 (")(您可能需要将它们进行 URL 编码为 %22),Windows 将可以使用完整路径:

<a href="file:///%22C:\Documents and Settings\user123\My Documents\testing\someFile.txt%22">link</a>

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:

<a href="file:///%22C:\Documents and Settings\user123\My Documents\testing\someFile.txt%22">link</a>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文