Package org.eclipse.jetty.servlet
Class DefaultServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.eclipse.jetty.servlet.DefaultServlet
-
- All Implemented Interfaces:
java.io.Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
,ResourceService.WelcomeFactory
,ResourceFactory
public class DefaultServlet extends javax.servlet.http.HttpServlet implements ResourceFactory, ResourceService.WelcomeFactory
The default servlet.This servlet, normally mapped to /, provides the handling for static content, OPTION and TRACE methods for the context. The following initParameters are supported, these can be set either on the servlet itself or as ServletContext initParameters with a prefix of org.eclipse.jetty.servlet.Default. :
acceptRanges If true, range requests and responses are supported dirAllowed If true, directory listings are returned if no welcome file is found. Else 403 Forbidden. welcomeServlets If true, attempt to dispatch to welcome files that are servlets, but only after no matching static resources could be found. If false, then a welcome file must exist on disk. If "exact", then exact servlet matches are supported without an existing file. Default is true. This must be false if you want directory listings, but have index.jsp in your welcome file list. redirectWelcome If true, welcome files are redirected rather than forwarded to. gzip If set to true, then static content will be served as gzip content encoded if a matching resource is found ending with ".gz" (default false) (deprecated: use precompressed) precompressed If set to a comma separated list of encoding types (that may be listed in a requests Accept-Encoding header) to file extension mappings to look for and serve. For example: "br=.br,gzip=.gz,bzip2=.bz". If set to a boolean True, then a default set of compressed formats will be used, otherwise no precompressed formats. resourceBase Set to replace the context resource base resourceCache If set, this is a context attribute name, which the servlet will use to look for a shared ResourceCache instance. relativeResourceBase Set with a pathname relative to the base of the servlet context root. Useful for only serving static content out of only specific subdirectories. pathInfoOnly If true, only the path info will be applied to the resourceBase stylesheet Set with the location of an optional stylesheet that will be used to decorate the directory listing html. etags If True, weak etags will be generated and handled. maxCacheSize The maximum total size of the cache or 0 for no cache. maxCachedFileSize The maximum size of a file to cache maxCachedFiles The maximum number of files to cache useFileMappedBuffer If set to true, it will use mapped file buffer to serve static content when using NIO connector. Setting this value to false means that a direct buffer will be used instead of a mapped file buffer. This is set to false by default by this class, but may be overridden by eg webdefault.xml cacheControl If set, all static content will have this value set as the cache-control header. otherGzipFileExtensions Other file extensions that signify that a file is already compressed. Eg ".svgz" encodingHeaderCacheSize Max entries in a cache of ACCEPT-ENCODING headers.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private CachedContentFactory
_cache
private ContextHandler
_contextHandler
private ServletHolder
_defaultHolder
private MimeTypes
_mimeTypes
private java.lang.String
_relativeResourceBase
private Resource
_resourceBase
private ResourceService
_resourceService
private javax.servlet.ServletContext
_servletContext
private ServletHandler
_servletHandler
private Resource
_stylesheet
private boolean
_useFileMappedBuffer
private boolean
_welcomeExactServlets
private java.lang.String[]
_welcomes
private boolean
_welcomeServlets
static java.lang.String
CONTEXT_INIT
private static Logger
LOG
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description DefaultServlet()
DefaultServlet(ResourceService resourceService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
protected void
doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected void
doOptions(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
protected void
doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
protected void
doTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
private boolean
getInitBoolean(java.lang.String name, boolean dft)
private int
getInitInt(java.lang.String name, int dft)
java.lang.String
getInitParameter(java.lang.String name)
Resource
getResource(java.lang.String pathInContext)
get Resource to serve.java.lang.String
getWelcomeFile(java.lang.String pathInContext)
Finds a matching welcome file for the suppliedResource
.void
init()
protected ContextHandler
initContextHandler(javax.servlet.ServletContext servletContext)
Compute the field _contextHandler.
In the case where the DefaultServlet is deployed on the HttpService it is likely that this method needs to be overwritten to unwrap the ServletContext facade until we reach the original jetty's ContextHandler.private CompressedContentFormat[]
parsePrecompressedFormats(java.lang.String precompressed, boolean gzip)
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doPut, getLastModified, service, service
-
-
-
-
Field Detail
-
CONTEXT_INIT
public static final java.lang.String CONTEXT_INIT
- See Also:
- Constant Field Values
-
LOG
private static final Logger LOG
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
_resourceService
private final ResourceService _resourceService
-
_servletContext
private javax.servlet.ServletContext _servletContext
-
_contextHandler
private ContextHandler _contextHandler
-
_welcomeServlets
private boolean _welcomeServlets
-
_welcomeExactServlets
private boolean _welcomeExactServlets
-
_resourceBase
private Resource _resourceBase
-
_cache
private CachedContentFactory _cache
-
_mimeTypes
private MimeTypes _mimeTypes
-
_welcomes
private java.lang.String[] _welcomes
-
_stylesheet
private Resource _stylesheet
-
_useFileMappedBuffer
private boolean _useFileMappedBuffer
-
_relativeResourceBase
private java.lang.String _relativeResourceBase
-
_servletHandler
private ServletHandler _servletHandler
-
_defaultHolder
private ServletHolder _defaultHolder
-
-
Constructor Detail
-
DefaultServlet
public DefaultServlet(ResourceService resourceService)
-
DefaultServlet
public DefaultServlet()
-
-
Method Detail
-
init
public void init() throws javax.servlet.UnavailableException
- Overrides:
init
in classjavax.servlet.GenericServlet
- Throws:
javax.servlet.UnavailableException
-
parsePrecompressedFormats
private CompressedContentFormat[] parsePrecompressedFormats(java.lang.String precompressed, boolean gzip)
-
initContextHandler
protected ContextHandler initContextHandler(javax.servlet.ServletContext servletContext)
Compute the field _contextHandler.
In the case where the DefaultServlet is deployed on the HttpService it is likely that this method needs to be overwritten to unwrap the ServletContext facade until we reach the original jetty's ContextHandler.- Parameters:
servletContext
- The servletContext of this servlet.- Returns:
- the jetty's ContextHandler for this servletContext.
-
getInitParameter
public java.lang.String getInitParameter(java.lang.String name)
- Specified by:
getInitParameter
in interfacejavax.servlet.ServletConfig
- Overrides:
getInitParameter
in classjavax.servlet.GenericServlet
-
getInitBoolean
private boolean getInitBoolean(java.lang.String name, boolean dft)
-
getInitInt
private int getInitInt(java.lang.String name, int dft)
-
getResource
public Resource getResource(java.lang.String pathInContext)
get Resource to serve. Map a path to a resource. The default implementation calls HttpContext.getResource but derived servlets may provide their own mapping.- Specified by:
getResource
in interfaceResourceFactory
- Parameters:
pathInContext
- The path to find a resource for.- Returns:
- The resource to serve.
-
doGet
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doGet
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
doPost
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doPost
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
doTrace
protected void doTrace(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doTrace
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
doOptions
protected void doOptions(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, java.io.IOException
- Overrides:
doOptions
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
java.io.IOException
-
destroy
public void destroy()
- Specified by:
destroy
in interfacejavax.servlet.Servlet
- Overrides:
destroy
in classjavax.servlet.GenericServlet
-
getWelcomeFile
public java.lang.String getWelcomeFile(java.lang.String pathInContext)
Description copied from interface:ResourceService.WelcomeFactory
Finds a matching welcome file for the suppliedResource
.- Specified by:
getWelcomeFile
in interfaceResourceService.WelcomeFactory
- Parameters:
pathInContext
- the path of the request- Returns:
- The path of the matching welcome file in context or null.
-
-