You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alex Colic <al...@pop-ware.com> on 2001/04/03 16:23:10 UTC

How to get around a tricky situation.

Hi,

I need some advice on how I might fix a problem with one of our web apps. We
farmed out an app that works ok except that the web pages which are created
by servlets are looking for images in the tomcat root images directory. This
presents a problem in that if I create a war of our app I also have to
distribute and copy the images over to the root images directory.

Can I set up my web.xml file so that when a web page looks for an image in
the /images directory it actually pulls them out of my myWebApp/images
directory.

What I am trying to achieve is one war file that I can use to distribute our
app without having the customer copy images over to the root/images
directory.

Thanks for any help.

Regards

Alex Colic-0132


Re: How to get around a tricky situation.

Posted by Ed Gomolka <eg...@gyldan.com>.
On Tuesday 03 April 2001 09:23, Alex Colic wrote:
> Hi,
>
> I need some advice on how I might fix a problem with one of our web apps.
> We farmed out an app that works ok except that the web pages which are
> created by servlets are looking for images in the tomcat root images
> directory. This presents a problem in that if I create a war of our app I
> also have to distribute and copy the images over to the root images
> directory.
>
> Can I set up my web.xml file so that when a web page looks for an image in
> the /images directory it actually pulls them out of my myWebApp/images
> directory.
>
You best bet is to change your source code to pick up the
path dynamically.
You can use something like the following to
determine the image path relative to the base of your context:
============
    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
        servletContext = config.getServletContext();
        String contextPath = servletContext.getRealPath("/");
        String imagesDirectory = contextPath + "images";
    }

-- 

Ed Gomolka
(egomolka@gyldan.com)