8

I want to be able to access a folder from my tomcat webapps folder so that I can give someone a URL like:

http://localhost:8080/myFolder/myFile.f

And in a web browser if they point to this they should start downloading the file.

But in reality I get a 404 error when I try to point to this location.

How can I solve this or get around it.

Ankur
  • 2,369
  • 7
  • 22
  • 24

2 Answers2

9

You can also place the folder inside the default servlet. For your example, the folder would be:

/webapps/ROOT/myFolder/
G__
  • 294
  • 2
  • 9
  • This is neat, but somehow does not work for me with symbolic link underneath. What works for me is a symbolic link in /webapps. In conjuntion with https://serverfault.com/a/143683/142353 I managed to serve a directory somewhere else on the host system (/var/log/tomcat6) :D – user1768130 Jul 19 '18 at 08:38
6

Make your folder a web application: put a WEB-INF folder with a minimal web.xml file into your folder, the web.xml file could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>

Then configure Tomcat to deploy the webapp with the URI you want.

  • OK this worked for me. Basically "have a WEB-INFO/web.xml file" then within tomcat, something like `mkdir webapps//myFolder` then touch something there. It should become available on "http://your_hostname:8080//myFolder/MyFile.f" – rogerdpack Mar 11 '15 at 14:14
  • Found a neat extension: "enabling directory index". see http://wiki.metawerx.net/wiki/EnablingOrDisablingDirectoryListingsUsingWeb.xml – user1768130 Jul 19 '18 at 08:37