Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Default Servlet a (de facto) standard?

Tags:

java

servlets

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?

like image 898
Jim Downing Avatar asked Nov 02 '09 12:11

Jim Downing


2 Answers

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.

like image 134
BalusC Avatar answered Oct 08 '22 08:10

BalusC


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.

like image 3
ZZ Coder Avatar answered Oct 08 '22 07:10

ZZ Coder