If you have only a small number of static file types, then you could also
do:
  <servlet-mapping>
     <servlet-name>default</servlet-name>
      <url-pattern>*.gif</url-pattern>
  </servlet-mapping>
  <!-- repeat as necessary -->

Another trick is to include in your servlet something like:
  ServletContext cntx = getServletContext();
  URL resource = cntx.getResource(request.getPathInfo());
  if(resource != null) { // physical file exists
    RequestDispatcher rd = cntx.getNamedDispatcher("default");
    rd.forward(request, response);
    return;
  }


"Tim Funk" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> That is because your have overridden the default servlet. It is now your
> servlet's job to also serve static content.
>
> A simple workaround: Extend the DefaultServlet, then use super.doGet(),
> super.doPost() ... when your servlet doesn't want the mapping.
>
> -Tim
>
> Mike Curwen wrote:
>
> > Apologies if this is a dupe. I just realized I sent the first one from
> > an account that is not subscribed....
> >
> > **************************************************
> >
> > Once more with feeling?
> >
> > Bill Barker, John Turner and others might recognize this question. Yes,
> > it's me AGAIN.
> >
> > httpd.conf:
> >
> > <VirtualHost 205.200.100.109>
> >      ServerName foo.myfoo.com
> >      ServerAlias www.foo.myfoo.com
> >      DocumentRoot /home/webhome/myfoo
> >      #deny WEB-INF
> >      <Location "/WEB-INF">
> >          AllowOverride None
> >          deny from all
> >      </Location>
> >      JkMount /* tomcat1
> >      ErrorLog /var/log/myfoo/error_log
> >      CustomLog /var/log/myfoo/access_log combined
> > </VirtualHost>
> >
> > server.xml:
> >
> > <Context path="" docBase="/home/webhome/myfoo/"
> > defaultSessionTimeout="60" />
> >
> > web.xml in myfoo/WEB-INF:
> >
> > <servlet-mapping>
> >   <servlet-name>Translator</servlet-name>
> >   <url-pattern>/</url-pattern>
> > </servlet-mapping>
> >
> >
> > Result:
> >
> > http://foo.myfoo.com/hello/there
> >
> > 1. Apache passes everything to Tomcat
> > 2. Tomcat can't recognize a mapped servlet, and uses the default
> > 3. My Translator servlet will translate 'foo' from the subdomain and the
> > /hello/there URI into a form like "/real_servlet?a=foo&b=hello&c=there",
> > which is then redirected to.
> > 4. Request for foo.myfoo.com/real_servlet?a=foo&b=hello&c=there
> > 5. Apache passes everything to Tomcat
> > 6. the real_servlet is a recognized mapping, and everything is
> > wonderful.
> >
> >
> >
> > Except when it comes to the HTML.
> >
> > <img src="/img/foo.gif" />
> > <link rel="stylesheet" href="/myfoo.css" type="text/css">
> >
> > These requests are *also* being sent through my translator servlet,
> > which of course, results in little red "X" images and no CSS.
> >
> > The solution I've come up with is to serve all images/css/etc from a
> > completely separate virtual host.
> >
> > <VirtualHost 205.200.100.109>
> >      ServerName img.myfoo.com
> >      DocumentRoot /home/webhome/myfoo
> >      #deny WEB-INF
> >      <Location "/WEB-INF">
> >          AllowOverride None
> >          deny from all
> >      </Location>
> >      ErrorLog /var/log/myfoo/img_error_log
> >      CustomLog /var/log/myfoo/img_access_log combined
> > </VirtualHost>
> >
> > Here, I forward nothing to Tomcat, and let apache serve whatever
> > requests it gets. And of course, I'd construct my links in such a
> > manner:
> >
> > <img src="http://img.myfoo.com/img/foo.gif"; />
> > <link rel="stylesheet" href="http://img.myfoo.com/myfoo.css";
> > type="text/css">
> >
> >
> > Finally the question:
> > Is there a way around having to use the separate virtual host to serve
> > static content?
> >
> >
> > -------------------------------------------
> > Mike Curwen                    204-885-7733
> > Intermediate Programmer       www.gb-im.com
> > -------------------------------------------
> >   ____   ____            ___   __  __
> >  / ___| | __ )          |_ _| |  \/  |
> > | |  _  |  _ \   _____   | |  | |\/| |
> > | |_| | | |_) | |_____|  | |  | |  | |
> >  \____| |____/          |___| |_|  |_|
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to