You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Bill Barker <wb...@wilshire.com> on 2002/01/22 02:11:03 UTC

Re: The problem with "/"

Actually, the default-servlet is supposed to handle requests for static
resources.  It sounds like what you want is something like:
<servlet-mapping>
  <servlet-name>default</servlet-name>
   <url-pattern>*.gif</url-pattern>
</servlet-mapping>
----- Original Message -----
From: "Peter Sojan" <il...@gmx.net>
To: <to...@jakarta.apache.org>
Sent: Monday, January 21, 2002 5:22 PM
Subject: The problem with "/"


>
> Hi!
>
> In the latest release notes (4.0.2-b2) I´ve seen the following:
> -------------------
> StandardContextMapper: '/' is now handled as a special case.
> -------------------
> I wondered if this indicates that tomcat now behaves spec
> compliant regarding the "default-servlet". However, I found
> out that this still seems to be  not the case:
>
> Thus in my app "infovis" if I say:
>
>  <servlet-mapping>
>     <servlet-name>MainServlet</servlet-name>
>     <url-pattern>/</url-pattern>
>  </servlet-mapping>
>
> then requests should be handled as follows:
>
> http://bla:8080/infovis/ => MainServlet
> http://bla:8080/infovis/anyNONnexistingpath => MainServlet
>
>
> http://bla:8080/infovis/EXISTINGPATH => Existing resource !!!
>
> current tomcat IMHO violates the last rule, which is especially
> irritating when servlets include links to static content like
> pictures -> tomcat will in all cases where an URL relates to
> a >existing static resource (i.e. not a valid servlet mapping!!!)<
> to the default servlet.
>
> Will this be fixed in the coming release !?
>
> Thx
> Peter
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The problem with "/"

Posted by Peter Sojan <il...@gmx.net>.
On Tue, Jan 22, 2002 at 02:00:08AM -0800, Bill Barker wrote:

I thought of something similar, but your solution is way more 
elegant. Thank you! 

> I'm not primarily a 4.x developer, but in theory the following should work:
> 
>   URL res = config.getResource(request.getPathInfo());
>   if(res != null) {
>     RequestDispatcher rd = config.getNamedDispatcher("default");
>     rd.forward(request,response);
>     return;
>   }

Peter

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The problem with "/"

Posted by Bill Barker <wb...@wilshire.com>.
I'm not primarily a 4.x developer, but in theory the following should work:

  URL res = config.getResource(request.getPathInfo());
  if(res != null) {
    RequestDispatcher rd = config.getNamedDispatcher("default");
    rd.forward(request,response);
    return;
  }
// Your processing here.

Undeclared variables correspond to their JSP counterparts.

4.x developers who want to gloat (and you know who you are, Craig ;), should
note that none of this is (currently) possible to do under 3.3.
----- Original Message -----
From: "Peter Sojan" <il...@gmx.net>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
Sent: Monday, January 21, 2002 6:30 PM
Subject: Re: The problem with "/"


>
> Thank you for your hint!
>
> Now I understand, that with my setting:
>
> ----------------------------------
> <servlet-mapping>
>     <servlet-name>MyMainServlet</servlet-name>
>     <url-pattern>/</url-pattern>
>  </servlet-mapping>
> ----------------------------------
>
> I override the default configuration which is:
>
> ----------------------------------
>  <servlet-mapping>
>     <servlet-name>default</servlet-name>
>     <url-pattern>/</url-pattern>
>   </servlet-mapping>
> ----------------------------------
>
> If I want to handle all requests for non-existent resources with
> my "MyMainServlet" and all static-existent (non-servlet) resources
> with "DefaultServlet", your solution should work If I can forsee
> every type of static resource I will offer in my webapp.
>
> So I would have to write mappings for *.gif, *.jpg, *.png, *.pdf,
> *.bla, and so on. I think the way the spec handles this issue, is
> that if I do a mapping on "/", then requests for static-existent
> content would still be served by the container without invoking
> my MyMainServlet. However since the tomcat solution is to handle
> static content with a DefaultServlet, I will always loose this
> functionality when I override the "/" mapping with my own servlet.
>
> Any suggestions for a workaround!?
> Thx
> Peter
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The problem with "/"

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 22 Jan 2002, Peter Sojan wrote:

> Date: Tue, 22 Jan 2002 03:30:43 +0100
> From: Peter Sojan <il...@gmx.net>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>
> To: Tomcat Developers List <to...@jakarta.apache.org>
> Subject: Re: The problem with "/"
>
>
> Thank you for your hint!
>
> Now I understand, that with my setting:
>
> ----------------------------------
> <servlet-mapping>
>     <servlet-name>MyMainServlet</servlet-name>
>     <url-pattern>/</url-pattern>
>  </servlet-mapping>
> ----------------------------------
>
> I override the default configuration which is:
>
> ----------------------------------
>  <servlet-mapping>
>     <servlet-name>default</servlet-name>
>     <url-pattern>/</url-pattern>
>   </servlet-mapping>
> ----------------------------------
>
> If I want to handle all requests for non-existent resources with
> my "MyMainServlet" and all static-existent (non-servlet) resources
> with "DefaultServlet", your solution should work If I can forsee
> every type of static resource I will offer in my webapp.
>
> So I would have to write mappings for *.gif, *.jpg, *.png, *.pdf,
> *.bla, and so on. I think the way the spec handles this issue, is
> that if I do a mapping on "/", then requests for static-existent
> content would still be served by the container without invoking
> my MyMainServlet. However since the tomcat solution is to handle
> static content with a DefaultServlet, I will always loose this
> functionality when I override the "/" mapping with my own servlet.
>
> Any suggestions for a workaround!?

How about just serving the content yourself?  It's not difficult to do.

> Thx
> Peter
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: The problem with "/"

Posted by Peter Sojan <il...@gmx.net>.
Thank you for your hint!

Now I understand, that with my setting: 

----------------------------------
<servlet-mapping>
    <servlet-name>MyMainServlet</servlet-name>
    <url-pattern>/</url-pattern>
 </servlet-mapping>
----------------------------------

I override the default configuration which is:

----------------------------------
 <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
----------------------------------

If I want to handle all requests for non-existent resources with 
my "MyMainServlet" and all static-existent (non-servlet) resources
with "DefaultServlet", your solution should work If I can forsee 
every type of static resource I will offer in my webapp. 

So I would have to write mappings for *.gif, *.jpg, *.png, *.pdf, 
*.bla, and so on. I think the way the spec handles this issue, is 
that if I do a mapping on "/", then requests for static-existent 
content would still be served by the container without invoking 
my MyMainServlet. However since the tomcat solution is to handle 
static content with a DefaultServlet, I will always loose this  
functionality when I override the "/" mapping with my own servlet.

Any suggestions for a workaround!?
Thx
Peter


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>