Discussions

Web tier: servlets, JSP, Web frameworks: Access text file outside Web Application

  1. Access text file outside Web Application (2 messages)

    I am developing a web application that has to retrieve and show users a text file. A simple link to a .txt file; however, the file is located in another directory on the host (a shared drive between all clusters). How do I get and retrieve this file through a servlet? I know all paths are relative within my application. For clarity my web applications path is /opt/bea/myDomain/myEntApp/myWebApp, I need to access a text file in the /opt/reports/files/ps/ directory. In my web app I have a link 'View Text' which will retrieve a text file from the above directory, ps, and present it to the user. Thanks.
  2. Well, I don´t know if that´s possible...
    But couldn´t you point this link to a Servtet in the 2º app, and than recover the file, using the getRealPath() method?
    I think it could work...
  3. Write a FileLoaderServlet that does the following:

    1. Load the file using regular java.io.
    2. Send the file to the browser using the response's OutputStream.

    Be very very careful when you write this servlet, and make sure it can only load a specific text file or text files in specific directories. Otherwise, someone could theoretically use the FileLoaderServlet to download any file anywhere on your server.