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.

Posted on 2012-08-30
Last Modified: 2012-09-10
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?
Question by:gdkinney_2
    LVL 20

    Expert Comment

    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?

    Author Comment

    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.
    LVL 82

    Expert Comment

    by:Dave Baldwin
    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.
    LVL 10

    Accepted Solution

    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.
    LVL 12

    Expert Comment

    by:Sharon Seth
    All resources in a web app should be put in the deployed folder . Try putting your file somewhere in WEB-INF

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now