Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
679 views
in Technique[技术] by (71.8m points)

html - Linking to local content in a web application

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...