But what about welcome-files and static resources? How they can be accessed if I define the default servlet?
The container will use for welcome-file's for appending to URIs when there is a request for a URI that corresponds to a directory entry in the WAR not mapped to a Web component.
Frits Walraven wrote:For the static resources it makes sense: they all map to the default servlet.
How would all static resources map to a servlet?
The path used for mapping to a servlet is the request URL from the request
object minus the context path and the path parameters. The URL path mapping
rules below are used in order. The first successful match is used with no further
1. The container will try to find an exact match of the path of the request to the
path of the servlet. A successful match selects the servlet.
2. The container will recursively try to match the longest path-prefix. This is done
by stepping down the path tree a directory at a time, using the '/' character as
a path separator. The longest match determines the servlet selected.
3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet
container will try to match a servlet that handles requests for the extension.
An extension is defined as the part of the last segment after the last '.' character.
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.
So the JSP files are reachable, as they match the rule no. 3 - they service is passed to the JSP Container (in Tomcat world it is Jasper), right?
Frits Walraven wrote:The mapping of the URL (http://localhost:8080/AppName/fooStuff/foo.html) will follow the rules as defined above here and will end up in rule number 4. If you have defined a default servlet (and we have) the request will mapped to the default servlet (nl.errors.DefaultServlet).
Ofcourse, there might be exceptions, depending on the design requirement. But in general default servlets are not a good idea, else, you cannot really have any static resources, right?