The default resource-serving servlet for most web applications, used to serve static resources such as HTML pages and images.
This servlet is intended to be mapped to / e.g.:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
It can be mapped to sub-paths, however in all cases resources are served from the web application resource root using
the full path from the root of the web application context.
e.g. given a web application structure:
/context
/images
tomcat2.jpg
/static
/images
tomcat.jpg
... and a servlet mapping that maps only /static/* to the default servlet:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
Then a request to /context/static/images/tomcat.jpg will succeed while a request to
/context/images/tomcat2.jpg will fail.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static enum | |
| protected static class | |
| private static class | |
| private static class | DefaultServlet.
This is secure in the sense that any attempt to use an external entity will trigger an exception. |
| private static class | DefaultServlet.
A class encapsulating the sorting of resources. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | allowPartialPut
Flag that indicates whether partial PUTs are permitted. |
| protected static final int | BUFFER_SIZE
Size of file transfer buffer in bytes. |
| protected DefaultServlet. | compressionFormats
List of compression formats to serve and their preference order. |
| protected String | contextXsltFile
Allow customized directory listing per context. |
| protected int | debug
The debugging detail level for this servlet. |
| private static final DocumentBuilderFactory | |
| protected String | fileEncoding
File encoding to be used when reading static files. |
| private transient Charset | |
| protected static final Ranges | FULL
Full range marker. |
| protected String | globalXsltFile
Allow customized directory listing per instance. |
| private static final ContentRange | |
| protected int | input
The input buffer size to use when serving resources. |
| protected boolean | listings
Should we generate directory listings? |
| protected String | localXsltFile
Allow customized directory listing per directory. |
| protected static final String | mimeSeparation
MIME multipart separation string |
| protected int | output
The output buffer size to use when serving resources. |
| protected String | readmeFile
Allow a readme file to be included. |
| protected boolean | readOnly
Read only flag. |
| protected transient WebResourceRoot | resources
The complete set of web application resources |
| private static final DefaultServlet. | |
| protected int | sendfileSize
Minimum size for sendfile usage in bytes. |
| private static final long | |
| protected boolean | showServerInfo
Flag to determine if server information is presented. |
| protected static final StringManager | sm
The string manager for this package. |
| protected boolean | sortListings
Flag to determine if resources should be sorted. |
| protected transient DefaultServlet. | sortManager
The sorting manager for sorting files and directories. |
| protected boolean | useAcceptRanges
Should the Accept-Ranges: bytes header be send with static resources? |
| private DefaultServlet. | useBomIfPresent
If a file has a BOM, should that be used in preference to fileEncoding? |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | Returns: true if the resource meets all the specified conditions, and false if any of
the conditions is not satisfied, in which case request processing is stoppedThe servlet request we are processing request, HttpServletResponse The servlet response we are creating response, WebResource The resource resource)Check if the conditions specified in the optional If headers are satisfied. |
| protected boolean | Returns: true if the resource meets the specified condition, and false if the condition
is not satisfied, in which case request processing is stoppedThe servlet request we are processing request, HttpServletResponse The servlet response we are creating response, WebResource The resource resource)Check if the if-match condition is satisfied. |
| protected boolean | Returns: true if the resource meets the specified condition, and false if the condition
is not satisfied, in which case request processing is stoppedThe servlet request we are processing request, HttpServletResponse The servlet response we are creating response, WebResource The resource resource)Check if the if-modified-since condition is satisfied. |
| protected boolean | Returns: true if the resource meets the specified condition, and false if the condition
is not satisfied, in which case request processing is stoppedThe servlet request we are processing request, HttpServletResponse The servlet response we are creating response, WebResource The resource resource)Check if the if-none-match condition is satisfied. |
| protected boolean | Returns: true if the resource meets the specified condition, and false if the condition
is not satisfied, in which case request processing is stoppedThe servlet request we are processing request, HttpServletResponse The servlet response we are creating response, WebResource The resource resource)Check if the if-unmodified-since condition is satisfied. |
| protected boolean | Returns: true if sendfile should be used (writing is then delegated to the endpoint)The Servlet request request, HttpServletResponse The Servlet response response, WebResource The resource resource, long The length which will be written (will be used only if range is null) length, Ranges.The range that will be written rangeCheck if sendfile can be used. |
| private static Comparator | |
| protected void | copy(InputStream
The input stream to read the source resource from is, ServletOutputStream The output stream to write to ostream)Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| protected void | copy(InputStream
The input stream to read the source resource from is, PrintWriter The writer to write to writer, String The encoding to use when reading the source input stream encoding)Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| protected void | copy(WebResource
The source resource resource, long the resource length length, ServletOutputStream The output stream to write to ostream, Ranges.Range the client wanted to retrieve rangeCopy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| protected void | copy(WebResource
The source resource resource, long the resource length length, ServletOutputStream The output stream to write to ostream, Ranges Enumeration of the ranges the client wanted to retrieve ranges, String Content type of the resource contentType)Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| protected IOException | Returns: Exception which occurred during processingThe input stream to read from istream, ServletOutputStream The output stream to write to ostream)Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| protected IOException | Returns: Exception which occurred during processingThe reader to read from reader, PrintWriter The writer to write to writer)Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| protected IOException | Returns: Exception which occurred during processingThe input stream to read from istream, ServletOutputStream The output stream to write to ostream, long Start of the range which will be copied start, long End of the range which will be copied end)Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception). |
| public void | destroy()
Overrides jakarta. Implements jakarta. Finalize this servlet. |
| protected String | |
| protected void | doDelete(HttpServletRequest
The servlet request we are processing req, HttpServletResponse The servlet response we are creating resp)Overrides jakarta. Process a DELETE request for the specified resource. |
| private void | |
| protected void | doGet(HttpServletRequest
The servlet request we are processing request, HttpServletResponse The servlet response we are creating response)Overrides jakarta. Process a GET request for the specified resource. |
| protected void | doHead(HttpServletRequest
The servlet request we are processing request, HttpServletResponse The servlet response we are creating response)Overrides jakarta. Process a HEAD request for the specified resource. |
| protected void | doOptions(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Override default implementation to ensure that TRACE is correctly handled. |
| protected void | doPost(HttpServletRequest
The servlet request we are processing request, HttpServletResponse The servlet response we are creating response)Overrides jakarta. Process a POST request for the specified resource. |
| protected void | doPut(HttpServletRequest
The servlet request we are processing req, HttpServletResponse The servlet response we are creating resp)Overrides jakarta. Process a PUT request for the specified resource. |
| protected File | Returns: the associated file objectThe Servlet request req, ContentRange The range that will be written range, String The path path)Handle a partial PUT. |
| protected Source | Returns: the source for the specified directoryThe directory to search directory)Return a Source for the xsl template (if possible). |
| protected String | Returns: The result of callingWebResource#getETag() on the given resourceThe resource for which an entity tag is required. resource)Provides the entity tag (the ETag header) for the given resource. |
| private List | |
| private DefaultServlet. | Returns: The best matching precompressed resource or null if no match was found.The servlet request we are processing request, List<DefaultServlet.List of available precompressed resources. precompressedResourcesMatch the client preferred encoding formats to the available precompressed resources. |
| private static long | |
| private char | Returns: Either 'A' or 'D', to indicate "ascending" or "descending" sort order.The order that is currently being applied order,The column that will be rendered. column)Gets the ordering character to be used for a particular column. |
| protected String | Returns: the prefix to apply to all resources in the listing.the request to determine the path for request)Determines the appropriate path to prepend resources with when generating directory listings. |
| protected String | Returns: the readme for the specified directoryThe directory to search directory, String The readme encoding encoding)Get the readme file as a string. |
| protected String | Returns: the relative pathThe servlet request we are processing request)Return the relative path associated with this servlet. |
| protected String | |
| private static long | |
| public void | |
| private static boolean | |
| private DefaultServlet. | |
| protected ContentRange | Returns: the partial content-range,null if the content-range header was invalid or #IGNORE if
there is no header to processThe servlet request we are processing request, HttpServletResponse The servlet response we are creating response)Parse the content-range header. |
| protected Ranges | Returns: a list of ranges,null if the range header was invalid or #FULL if the Range header
should be ignored.The servlet request we are processing request, HttpServletResponse The servlet response we are creating response, WebResource The resource resource)Parse the range header. |
| private boolean | |
| private static Charset | |
| protected InputStream | Returns: the input stream with the rendered outputThe HttpServletRequest being served request, String The path contextPath, WebResource The resource resource, String The encoding to use to process the readme (if any) encoding)Decide which way to render. |
| protected InputStream | Returns: the HTML dataThe HttpServletRequest being served request, String Context path to which our internal paths are relative contextPath, WebResource The associated resource resource, String The encoding to use to process the readme (if any) encoding)Return an InputStream to an HTML representation of the contents of this directory. |
| protected String | Returns: the formatted sizeFile size (in bytes) size)Render the specified file size (in bytes). |
| protected InputStream | Returns: the XML dataThe HttpServletRequest being served request, String Context path to which our internal paths are relative contextPath, WebResource The associated resource resource, Source The XSL stylesheet xsltSource, String The encoding to use to process the readme (if any) encoding)Return an InputStream to an XML representation of the contents this directory. |
| protected String | |
| private Source | |
| protected void | |
| protected void | serveResource(HttpServletRequest
The servlet request we are processing request, HttpServletResponse The servlet response we are creating response, boolean Should the content be included? content, String The encoding to use if it is necessary to access the source as characters rather than as
bytes inputEncoding)Serve the specified resource, optionally including the data content. |
| protected void | service(HttpServletRequest
the req, HttpServletResponse HttpServletRequest object that contains the request the client made of the servletthe resp)HttpServletResponse object that contains the response the servlet returns to the clientOverrides jakarta. Receives standard HTTP requests from the public |
| private static void | |
| private static boolean | |
| private static boolean | |
| private File | |
| private File |