You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Zengfa Gao <zf...@yahoo.com> on 2008/04/17 17:48:47 UTC

Using DefaultServlet for directory outside of webapps

Hi,

For our application, we want to list/show a list of
gif files. Currently we are using DefaultServlet with
listings=true (web.xml). As the result, we can list
the names of the file, and open the gif file under the
our.war directory.

For security reason, we are trying to list/show gif
under other directory, not the directory of our.war.
Is any setting for us to redirectory DefaultServlet to
look at other defined directory? For example, if we
put files under /var/opt/ourshare directory, how can
we do it?

Thanks a lot!

Jeff


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Using DefaultServlet for directory outside of webapps

Posted by NBW <em...@gmail.com>.
You could write a simple servlet to serve up these images from any
accessible file system. The URL for it would look something like this:

http://yourtomcatserver/yourwebappcontext/getImage?name=Foo.gif

The the servlet would know what directory to look for images in and handle
streaming them out to the client. That would be a very flexible way of
solving the problem.

On Thu, Apr 17, 2008 at 11:48 AM, Zengfa Gao <zf...@yahoo.com> wrote:

> Hi,
>
> For our application, we want to list/show a list of
> gif files. Currently we are using DefaultServlet with
> listings=true (web.xml). As the result, we can list
> the names of the file, and open the gif file under the
> our.war directory.
>
> For security reason, we are trying to list/show gif
> under other directory, not the directory of our.war.
> Is any setting for us to redirectory DefaultServlet to
> look at other defined directory? For example, if we
> put files under /var/opt/ourshare directory, how can
> we do it?
>
> Thanks a lot!
>
> Jeff
>
>
>
>  ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: Using DefaultServlet for directory outside of webapps

Posted by Zengfa Gao <zf...@yahoo.com>.
Chuck,

This a great idea. Now I am trying for find where to
put ourshare.xml file.

We are using Tomcat under Jboss, I didn't find
conf\Catalina yet.

Thanks a lot!

Jeff

--- "Caldarale, Charles R"
<Ch...@unisys.com> wrote:

> > From: Zengfa Gao [mailto:zfgao@yahoo.com] 
> > Subject: Using DefaultServlet for directory
> outside of webapps
> > 
> > Is any setting for us to redirectory
> DefaultServlet to
> > look at other defined directory? For example, if
> we
> > put files under /var/opt/ourshare directory, how
> can
> > we do it?
> 
> The easiest way is to define another <Context> with
> a docBase set to the
> location of the external directory.  For example,
> place the following in
> conf/Catalina/[host]/ourshare.xml:
> 
> <Context docBase="/var/opt/ourshare"/>
> 
> You can then forward or redirect references to the
> images to
> "/ourshare/[image].gif" and the DefaultServlet will
> handle them
> properly.
> 
>  - Chuck
> 
> 
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR
> OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended
> recipient. If you
> received this in error, please contact the sender
> and delete the e-mail
> and its attachments from all computers.
> 
>
---------------------------------------------------------------------
> To start a new topic, e-mail:
> users@tomcat.apache.org
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Using DefaultServlet for directory outside of webapps

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Zengfa Gao [mailto:zfgao@yahoo.com] 
> Subject: Using DefaultServlet for directory outside of webapps
> 
> Is any setting for us to redirectory DefaultServlet to
> look at other defined directory? For example, if we
> put files under /var/opt/ourshare directory, how can
> we do it?

The easiest way is to define another <Context> with a docBase set to the
location of the external directory.  For example, place the following in
conf/Catalina/[host]/ourshare.xml:

<Context docBase="/var/opt/ourshare"/>

You can then forward or redirect references to the images to
"/ourshare/[image].gif" and the DefaultServlet will handle them
properly.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Using DefaultServlet for directory outside of webapps

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeff,

Zengfa Gao wrote:
| For our application, we want to list/show a list of
| gif files. Currently we are using DefaultServlet with
| listings=true (web.xml). As the result, we can list
| the names of the file, and open the gif file under the
| our.war directory.
|
| For security reason, we are trying to list/show gif
| under other directory, not the directory of our.war.
| Is any setting for us to redirectory DefaultServlet to
| look at other defined directory? For example, if we
| put files under /var/opt/ourshare directory, how can
| we do it?

DefaultServlet cannot (currently) be targeted at a directory other than
the root of the webapp. You could probably subclass DefaultServlet and
modify its behavior such that you could re-target it to another
directory using init-param elements or something like that.

It looks like the init() method of DefaultServlet grabs a
ProxyDirContext from the application scope. I'm guessing that's a JNDI
context that is rooted in the current application's webapp root. By
overriding init() (make sure you call super.init()!), you could probably
re-target the "resources" member to another directory, and simply leave
everything else alone.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgHd+EACgkQ9CaO5/Lv0PBxiQCfboZKcnDiYpow+m30LFLlkSpO
b0IAnAolLNXhaJIe7491fDmaQQUPxVBW
=XxJE
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: forwarding across contexts?

Posted by Zengfa Gao <zf...@yahoo.com>.
Hi, 

When I asked the question, it seems that Fred had the
same problem before:

http://marc.info/?l=tomcat-user&m=108430682905359&w=2

If Fred is here, could you please tell me what you did
for your situation.

Thanks!

Jeff

--- Zengfa Gao <zf...@yahoo.com> wrote:

> Hi,
> 
> For our application, we want to list/show a list of
> gif files. Currently we are using DefaultServlet
> with
> listings=true (web.xml). As the result, we can list
> the names of the file, and open the gif file under
> the
> our.war directory.
> 
> For security reason, we are trying to list/show gif
> under other directory, not the directory of our.war.
> Is any setting for us to redirectory DefaultServlet
> to
> look at other defined directory? For example, if we
> put files under /var/opt/ourshare directory, how can
> we do it?
> 
> Thanks a lot!
> 
> Jeff
> 
> 
>      
>
____________________________________________________________________________________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now. 
>
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> 
>
---------------------------------------------------------------------
> To start a new topic, e-mail:
> users@tomcat.apache.org
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org