I have an <a> tag where the href property is pointing to a local file on my c drive at "c:\tmp". Is does not work in Tomcat 7.

I have an <a> tag where the href property is pointing to a local file on my c drive at "c:\tmp".  Is does not work in Tomcat 7.  

However if I take the page source and create a text file called "MyFile.html" and then I open it in IE or Firefox the <a> links work fine.   I am thinking there must be some security issue with Tomcat so that the webpage can't use the local file.

Any suggestions on how I can use local files for my <a> tag href properties and have the link work in Tomcat 7?
Who is Participating?
Pramod KumarCommented:
A java web application deployed in tomcat cannot access a file outside its deployed folder in a direct access mode as you are doing (by <a href="">). You have two options here:

1. Copy your file to the deployed folder and use a relative path (c:\temp\myfile.txt is an absolute path) under href.

2. If you are java programmer, then you can read any disk file using servlet and send to the user's browser.
What is the HTML source when the file is served by TomCat? Are you sure it's not rather a security feature of your browser not to refereence local files from the internet?
gdkinney_2Author Commented:
Its not the browser because I run the app in Tomcat and when the page is served I just take the page source and save it in a text file.  I then open it in the same browser outside of Tomcat and the links work fine.
Dave BaldwinFixer of ProblemsCommented:
Files and pages on a web server run under a limited user that is usually not allowed access outside the web directories.  You can open it in your browser because when you open it using a 'file://' protocol, it opens under your user.  If you try to include that link in a page coming from the web server, it will not work in your browser because current security rules prevent a web page from accessing the local computer.  http://code.google.com/p/browsersec/wiki/Part2
Sharon SethCommented:
All resources in a web app should be put in the deployed folder . Try putting your file somewhere in WEB-INF
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.