tomcat - access files outside of webapp

Discussion in 'Java' started by j, Jan 29, 2008.

  1. j

    j Guest

    I've written a little photo album servlet. Images can be uploaded and
    they are saved to some external directory: /some/dir/photos.

    I'd like to be able to access these photos using <img> tags, but don't
    know how to access anything outside of the external directory. On the
    other hand I don't want to save the images inside the webapps
    directory as the photos will all be lost every time I redeploy the

    I've created a static dispatcher servlet to access the images, but
    it's slower and seems to break browser caching. Thus I'd prefer to
    just use <img src="..."> tags if possible.

    Can anyone point me in the right direction here?

    j, Jan 29, 2008
    1. Advertisements

  2. j

    Arne Vajhøj Guest

    If you use a servlet to serve them, then you get access control - direct
    download and you have no control.

    But if you want to go that route, then you need to get that image
    directory served.

    Either by Apache outside of Tomcat or by Tomcat. I believe that
    you will need to add a new context to Tomcat to have Tomcat serve

    Arne Vajhøj, Jan 29, 2008
    1. Advertisements

  3. j

    j Guest

    Thanks much for providing some direction. After a little digging and
    trial-and-error, I was able to add the directory as a context and can
    now use <img> tags they way I wanted.
    j, Jan 29, 2008
  4. j

    umacts Guest

    I have the same problem. Can you please explain what you did and how
    you added a new context path?

    umacts, Mar 14, 2008
  5. Gilbert Rebhan, Mar 14, 2008
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.