DefaultServlet
The DefaultServlet implements the same request URI to filename mapping as the servlet container. There are two primary reasons to use the DefaultServlet:
- You can map the DefaultServlet to '/' to ensure that servlet mapping is always activated and there is a filter chain.
- The attribute NoMatchFile ensures that a file is always sent to the browser.
The example below clarifies these two items.
For security reasons, never put a file containing secret information (like a secret key or some Lua code) into the directory configured as "<docBase>
" in the navajo.xml file. This is because the DefaultFilter can easily access such a file. An exception is the WEB-INF directory inside the "<docBase>
" directory. The WEB-INF directory is protected against the DefaultFilter and cannot be accessed.
If you plan to share the same file(s) between several instances, use the FileReaderServlet instead. That way it is possible to place files outside the instances directory and make them accessible to multiple instances.
Classname:
ch::nevis::isiweb4::servlet::defaults::DefaultServlet
Library:
libDefaultServlets.so.1
Configuration
Name | Type, Usage Constraints, Defaults | Description |
---|---|---|
EntryURI | string; optional, basic connectivity; must start with / | If no matching file is found and the path info of the request is empty, a redirect with the configured value is sent to the browser. |
NoMatchFile | string; optional, basic feature; must start with / | If there is no matching file found, the file with the configured value will be sent. |
NoMatchFile.StatusCode | integer; optional;range: 100-599; default: 200 | Defines the HTTP status of the response, if no matching file is sent to the frontend. |
StatusCode | integer; optional, basic feature; min: 100, max: 600; default: 200 | Permits configuration of the HTTP status code of the response. |
MappingType | enum. [requestURI or pathinfo]; optional; default: requestURI | Enables mapping of request URIs to file names. Possible values are: requestURI: Mapping plays no role; pathinfo: The file name is the pathinfo part of the requestURI. |
SupportIfModifiedSinceHeader | boolean` optional, advanced; Default: false | If this flag is set, then the DefaultServlet can be further controlled by setting the If-Modified-Since header. This can be used for optimization. A document will only be served if it has been modified later than the time specified in the header. See RFC2616, section 14.25 for more details. |
Example
- Consider the following situation: To enforce an authentication, an IdentityCreationFilter will be mapped to
/*
. If the browser requests the URI/
, thatIdentityCreationFilteris not invoked because there is no matching servlet. By mapping the DefaultServlet to/*
, there is a matching servlet and therefore the IdentityCreationFilter is invoked. - Consider the following situation: All images are located in the directory
<docBase>/img
. Even if there is no matching file, an image should be sent. That can be done by configuring a DefaultServlet with the value/default.gif
for the attribute ‘NoMatchFile’, and mapping it to/img/*
.