This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes hyperlink to file on C: drive  does not work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "hyperlink to file on C: drive  does not work" Watch "hyperlink to file on C: drive  does not work" New topic
Author

hyperlink to file on C: drive does not work

Yuma Shankar
Greenhorn

Joined: Jun 07, 2005
Posts: 24
I have a JSP page where I am providing a hyperlink to a file on the C: drive as follows

<a href="C:\ReqImport\data.txt" target=_blank >Try this </a>

Nothing happens when I click this hyperlink.

When I scroll over the hyperlink I see the correct path "file:///C:/ReqImport/data.txt" in the status bar and when paste this path in my address bar, it does open up the file.

Any ideas why this file hyperlink does not work on this JSP page.

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It shouldn't work.
Browsers shouldn't grant access to resources on the client's hard drive.

Why would you want to link to local files from a webapp?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Yuma Shankar
Greenhorn

Joined: Jun 07, 2005
Posts: 24
The webapp is processing a data file on the users hard drive and then writing to an error file on the drive. So the hyperlink is for the user to open that error file.


Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The user should have to explicitly upload the file to be processed.
Think of the horrible things that a nefarious site could do if it were allowed to read and write from/to your hard drive.

If you want to bypass browser security, you might want to look into signed applets.
Yuma Shankar
Greenhorn

Joined: Jun 07, 2005
Posts: 24
Thanks Ben!
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
In theory the link "file:///C:/ReqImport/data.txt" should cause the browser to show the specified file (or prompt for download, depending on the file type).

Since this was a security concern, Internet Explorer 6 with Service Pack 1 now blocks the file protocol from being used by Internet sites. It will still work locally within Windows.

See also:
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/predefined/file.asp

Similarly, Netscape 7 blocks this by default. It is possible to unlock the file protocol in Netscape if you (personally) want it to work.

See also:
http://www.unc.edu/ais/directories/mozilla_fix.html

Of course, accessing client-local resources should never be a design 'feature' of your site!
[ December 30, 2005: Message edited by: Charles Lyons ]

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hyperlink to file on C: drive does not work
 
Similar Threads
Getting the server path
Ant Path problem
HTML hyperlink problem
<html:link/> not working with inbuilt ForwardAction class
download link in jsp ?