users@glassfish.java.net

Re: Servlets 3.0: Default servlet hides static resources

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Fri, 29 Jan 2010 10:29:13 -0800

On 01/29/10 12:20 AM, glassfish_at_javadesktop.org wrote:
>> You need to append a "/" to the action URI
>>
>
> That solved the problem, thanks a lot :)
>
> However, my original question is still unanswered:
> Is it the intent of the spec that the container should hide all static resources when mapping a servlet to "/"?
>

Yes, this is the intent of the Servlet spec, see Chapter 12 ("Mapping
Requests to Servlets"), Section 12.1 ("Use of URL Paths"):

  4. If neither of the previous three rules result in a servlet match,
  the container will attempt to serve content appropriate for the
  resource requested. If a "default" servlet is defined for the
  application, it will be used. Many containers provide an implicit
  default servlet for serving content.

As you may have noticed, GlassFish comes configured with its own
"default" servlet which is declared in the domain's default-web.xml:

  <servlet>
    <servlet-name>default</servlet-name>
    
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
  </servlet>

  <!-- The mapping for the default servlet -->
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

By default, this servlet, which is inherited by every web application
that has been deployed, is responsible for servicing any requests that
could not be mapped, including requests for static resources.

If you override the domain's "default" servlet with your own, then
your own servlet will handle those requests.


Jan

> The Servlet 3.0 spec says the following:
> [i]A string containing only the ’/’ character indicates the "default" servlet of the
> application. In this case the servlet path is the request URI minus the context path
> and the path info is null.[/i]
>
> It does not mention anything about static resource, however.
> [Message sent by forum member 'toker5' (java.net_at_reinseth.org)]
>
> http://forums.java.net/jive/thread.jspa?messageID=383634
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>