java - Accessing local files on Tomcat -
i'm using apache tomcat 7 , have servlet lists files in directory , allows users download files clicking on link.
here problem:
the files accessing in servlet not in project directory itself. in directory outside of tomcat directory itself
i.e.
project in /opt/apache-tomcat-7.0.53 files in /files/
when use anchor tag, can't reference using href="" because assumes directory within webcontent folder of project.
i tried doing href="file:///files/<file name>
not click on link download file must wrong.
anyone know how work around this?
edit: should point out isn't running on local machine. on server.
you're better off looking @ tomcat aliases. let mount external directories in web app's context, , have tomcat serve file directly.
addenda:
the part of url before :
called "scheme". examples include "http", "https", "ftp", "file".
the scheme tells browser "what do" rest of url, different schemes can have different formats after :
.
so, url starting file://
use "file" scheme. file scheme tells browser try , open filename specified rest of url. filename local filename. local browser. not server.
you never use file://
type of url on server based application, on client side application.
Comments
Post a Comment