tags:

views:

464

answers:

3

Related to this question, is the idea of a default servlet that serves static content a standard (even if a de facto one) across servlet containers, or does its use restrict deployment to Tomcat / Jetty?

For example, [1] shows this method for getting the default dispatcher:

 final RequestDispatcher rd = getServletContext().getNamedDispatcher("default");

From a quick search it seems that this would also work on Jetty. How broadly will this technique work for obtaining a default servlet? For the servlet containers that have a default servlet, is it always a static content servlet?

+3  A: 

It's not a standard, but without it appservers can't serve static content. It's just crucial.

[edit] I saw you edited and elaborated your question in a more clear manner:

For example, [1] shows this method for getting the default dispatcher:

final RequestDispatcher rd = getServletContext().getNamedDispatcher("default");

From a quick search it seems that this would also work on Jetty. How broadly will this technique work for obtaining a default servlet? For the servlet containers that have a default servlet, is it always a static content servlet?

In that case, it may be a defacto standard, but I wouldn't rely much on that and for sure not code against implementation specific details or even defacto standards. Ask yourself: what's the sense/value of dispatching the request to the defaultservlet? Exactly, nothing.

BalusC
A: 

As long as the servlet container standard is the Servlet API you can see there is no such thing as a DefaultServlet. Most widely used servlet container have some defaults to run out of the box. But it is no "standard" requirement to implement a certain interface or abstract class so the container can run. ( A container can run even without any servlet).

PeterMmm
+1  A: 

Servlet doesn't require a default servlet. However, the name must be "default" if one is defined. Can't imagine a container without default servlet. So you can assume it's standard.

See section SRV.11.1,

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.

ZZ Coder