public class ApplicationContext extends java.lang.Object implements ServletContext
ServletContext
that represents
a web application's execution environment. An instance of this class is
associated with each instance of StandardContext
.Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object> |
attributes
The context attributes for this context.
|
protected static boolean |
GET_RESOURCE_REQUIRE_SLASH |
protected static boolean |
STRICT_SERVLET_COMPLIANCE |
ORDERED_LIBS, TEMPDIR
Constructor and Description |
---|
ApplicationContext(StandardContext context)
Construct a new instance of this class, associated with the specified
Context instance.
|
Modifier and Type | Method and Description |
---|---|
FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
java.lang.Class<? extends Filter> filterClass)
Add filter to context.
|
FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
Filter filter)
Add filter to context.
|
FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
java.lang.String filterClass)
Add filter to context.
|
void |
addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
TODO SERVLET3 - Add comments
|
void |
addListener(java.lang.String className)
TODO SERVLET3 - Add comments
|
<T extends java.util.EventListener> |
addListener(T t)
TODO SERVLET3 - Add comments
|
ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
java.lang.Class<? extends Servlet> servletClass)
Add servlet to context.
|
ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
Servlet servlet)
Add servlet to context.
|
ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
java.lang.String servletClass)
Add servlet to context.
|
protected void |
clearAttributes()
Clear all application-created attributes.
|
<T extends Filter> |
createFilter(java.lang.Class<T> c)
TODO SERVLET3 - Add comments
|
<T extends java.util.EventListener> |
createListener(java.lang.Class<T> c)
TODO SERVLET3 - Add comments
|
<T extends Servlet> |
createServlet(java.lang.Class<T> c)
TODO SERVLET3 - Add comments
|
void |
declareRoles(java.lang.String... roleNames)
Add to the declared roles for this ServletContext.
|
java.lang.Object |
getAttribute(java.lang.String name)
Return the value of the specified context attribute, if any;
otherwise return
null . |
java.util.Enumeration<java.lang.String> |
getAttributeNames()
Return an enumeration of the names of the context attributes
associated with this context.
|
java.lang.ClassLoader |
getClassLoader()
Get the web application class loader associated with this ServletContext.
|
protected StandardContext |
getContext() |
ServletContext |
getContext(java.lang.String uri)
Return a
ServletContext object that corresponds to a
specified URI on the server. |
java.lang.String |
getContextPath()
Return the main path associated with this context.
|
java.util.Set<SessionTrackingMode> |
getDefaultSessionTrackingModes()
By default
SessionTrackingMode.URL is always supported, SessionTrackingMode.COOKIE is supported unless the cookies
attribute has been set to false for the context and SessionTrackingMode.SSL is supported if at least one of the connectors
used by this context has the attribute secure set to
true . |
int |
getEffectiveMajorVersion() |
int |
getEffectiveMinorVersion() |
java.util.Set<SessionTrackingMode> |
getEffectiveSessionTrackingModes()
Return the supplied value if one was previously set, else return the
defaults.
|
protected ServletContext |
getFacade()
Return the facade associated with this ApplicationContext.
|
FilterRegistration |
getFilterRegistration(java.lang.String filterName)
TODO SERVLET3 - Add comments
|
java.util.Map<java.lang.String,? extends FilterRegistration> |
getFilterRegistrations() |
java.lang.String |
getInitParameter(java.lang.String name)
Return the value of the specified initialization parameter, or
null if this parameter does not exist. |
java.util.Enumeration<java.lang.String> |
getInitParameterNames()
Return the names of the context's initialization parameters, or an
empty enumeration if the context has no initialization parameters.
|
JspConfigDescriptor |
getJspConfigDescriptor() |
int |
getMajorVersion()
Return the major version of the Java Servlet API that we implement.
|
java.lang.String |
getMimeType(java.lang.String file)
Return the MIME type of the specified file, or
null if
the MIME type cannot be determined. |
int |
getMinorVersion()
Return the minor version of the Java Servlet API that we implement.
|
RequestDispatcher |
getNamedDispatcher(java.lang.String name)
Return a
RequestDispatcher object that acts as a
wrapper for the named servlet. |
java.lang.String |
getRealPath(java.lang.String path)
Return the real path for a given virtual path, if possible; otherwise
return
null . |
RequestDispatcher |
getRequestDispatcher(java.lang.String path)
Return a
RequestDispatcher instance that acts as a
wrapper for the resource at the given path. |
java.net.URL |
getResource(java.lang.String path)
Return the URL to the resource that is mapped to a specified path.
|
java.io.InputStream |
getResourceAsStream(java.lang.String path)
Return the requested resource as an
InputStream . |
java.util.Set<java.lang.String> |
getResourcePaths(java.lang.String path)
Return a Set containing the resource paths of resources member of the
specified collection.
|
java.lang.String |
getServerInfo()
Return the name and version of the servlet container.
|
Servlet |
getServlet(java.lang.String name)
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
java.lang.String |
getServletContextName()
Return the display name of this web application.
|
java.util.Enumeration<java.lang.String> |
getServletNames()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
ServletRegistration |
getServletRegistration(java.lang.String servletName)
Obtain the details of the named servlet.
|
java.util.Map<java.lang.String,? extends ServletRegistration> |
getServletRegistrations()
TODO SERVLET3 - Add comments
|
java.util.Enumeration<Servlet> |
getServlets()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
SessionCookieConfig |
getSessionCookieConfig() |
java.lang.String |
getVirtualServerName()
Get the primary name of the virtual host on which this context is
deployed.
|
void |
log(java.lang.Exception exception,
java.lang.String message)
Deprecated.
As of Java Servlet API 2.1, use
log(String, Throwable) instead |
void |
log(java.lang.String message)
Writes the specified message to a servlet log file.
|
void |
log(java.lang.String message,
java.lang.Throwable throwable)
Writes the specified message and exception to a servlet log file.
|
void |
removeAttribute(java.lang.String name)
Remove the context attribute with the specified name, if any.
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Bind the specified value with the specified context attribute name,
replacing any existing value for that name.
|
boolean |
setInitParameter(java.lang.String name,
java.lang.String value)
Set the given initialisation parameter to the given value.
|
protected void |
setNewServletContextListenerAllowed(boolean allowed) |
void |
setSessionTrackingModes(java.util.Set<SessionTrackingMode> sessionTrackingModes)
Configures the available session tracking modes for this web application.
|
protected static final boolean STRICT_SERVLET_COMPLIANCE
protected static final boolean GET_RESOURCE_REQUIRE_SLASH
protected java.util.Map<java.lang.String,java.lang.Object> attributes
public ApplicationContext(StandardContext context)
context
- The associated Context instancepublic java.lang.Object getAttribute(java.lang.String name)
null
.getAttribute
in interface ServletContext
name
- Name of the context attribute to returnObject
containing the value of the attribute, or
null
if no attribute exists matching the given nameServletContext.getAttributeNames()
public java.util.Enumeration<java.lang.String> getAttributeNames()
getAttributeNames
in interface ServletContext
Enumeration
of attribute namesServletContext.getAttribute(java.lang.String)
public ServletContext getContext(java.lang.String uri)
ServletContext
object that corresponds to a
specified URI on the server. This method allows servlets to gain
access to the context for various parts of the server, and as needed
obtain RequestDispatcher
objects or resources from the
context. The given path must be absolute (beginning with a "/"),
and is interpreted based on our virtual host's document root.getContext
in interface ServletContext
uri
- Absolute URI of a resource on the serverServletContext
object that corresponds to the
named URL, or null if either none exists or the container wishes
to restrict this access.RequestDispatcher
public java.lang.String getContextPath()
getContextPath
in interface ServletContext
public java.lang.String getInitParameter(java.lang.String name)
null
if this parameter does not exist.getInitParameter
in interface ServletContext
name
- Name of the initialization parameter to retrieveString
containing the value of the initialization
parameterServletConfig.getInitParameter(java.lang.String)
public java.util.Enumeration<java.lang.String> getInitParameterNames()
getInitParameterNames
in interface ServletContext
Enumeration
of String
objects
containing the names of the context's initialization parametersServletConfig.getInitParameter(java.lang.String)
public int getMajorVersion()
getMajorVersion
in interface ServletContext
public int getMinorVersion()
getMinorVersion
in interface ServletContext
public java.lang.String getMimeType(java.lang.String file)
null
if
the MIME type cannot be determined.getMimeType
in interface ServletContext
file
- Filename for which to identify a MIME typeString
specifying the file's MIME typepublic RequestDispatcher getNamedDispatcher(java.lang.String name)
RequestDispatcher
object that acts as a
wrapper for the named servlet.getNamedDispatcher
in interface ServletContext
name
- Name of the servlet for which a dispatcher is requestedRequestDispatcher
object that acts as a wrapper for
the named servlet, or null
if the
ServletContext
cannot return a
RequestDispatcher
RequestDispatcher
,
ServletContext.getContext(java.lang.String)
,
ServletConfig.getServletName()
public java.lang.String getRealPath(java.lang.String path)
null
.getRealPath
in interface ServletContext
path
- The path to the desired resourceString
specifying the real path, or null if the
translation cannot be performedpublic RequestDispatcher getRequestDispatcher(java.lang.String path)
RequestDispatcher
instance that acts as a
wrapper for the resource at the given path. The path must begin
with a "/" and is interpreted as relative to the current context root.getRequestDispatcher
in interface ServletContext
path
- The path to the desired resource.RequestDispatcher
object that acts as a wrapper for
the resource at the specified path, or null
if the
ServletContext
cannot return a
RequestDispatcher
RequestDispatcher
,
ServletContext.getContext(java.lang.String)
public java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException
getResource
in interface ServletContext
path
- The path to the desired resourcenull
if
there is no resource at that pathjava.net.MalformedURLException
- if the path is not given
in the correct formpublic java.io.InputStream getResourceAsStream(java.lang.String path)
InputStream
. The
path must be specified according to the rules described under
getResource
. If no such resource can be identified,
return null
.getResourceAsStream
in interface ServletContext
path
- The path to the desired resource.InputStream
returned to the servlet, or
null
if no resource exists at the specified pathpublic java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
getResourcePaths
in interface ServletContext
path
- Collection pathpublic java.lang.String getServerInfo()
getServerInfo
in interface ServletContext
String
containing at least the servlet container
name and version number@Deprecated public Servlet getServlet(java.lang.String name)
javax.servlet.ServletContext
ServletContext
. In this version, this method always
returns null
and remains only to preserve binary
compatibility. This method will be permanently removed in a future
version of the Java Servlet API.
In lieu of this method, servlets can share information using the
ServletContext
class and can perform shared business logic
by invoking methods on common non-servlet classes.
getServlet
in interface ServletContext
name
- Not usednull
public java.lang.String getServletContextName()
getServletContextName
in interface ServletContext
@Deprecated public java.util.Enumeration<java.lang.String> getServletNames()
javax.servlet.ServletContext
Enumeration
of all the servlet names known to this context.
In this version, this method always returns an empty
Enumeration
and remains only to preserve binary
compatibility. This method will be permanently removed in a future
version of the Java Servlet API.getServletNames
in interface ServletContext
@Deprecated public java.util.Enumeration<Servlet> getServlets()
javax.servlet.ServletContext
Enumeration
of all the servlets known to this servlet
context. In this version, this method always returns an empty enumeration
and remains only to preserve binary compatibility. This method will be
permanently removed in a future version of the Java Servlet API.getServlets
in interface ServletContext
public void log(java.lang.String message)
log
in interface ServletContext
message
- Message to be written@Deprecated public void log(java.lang.Exception exception, java.lang.String message)
log(String, Throwable)
insteadlog
in interface ServletContext
exception
- Exception to be reportedmessage
- Message to be writtenpublic void log(java.lang.String message, java.lang.Throwable throwable)
log
in interface ServletContext
message
- Message to be writtenthrowable
- Exception to be reportedpublic void removeAttribute(java.lang.String name)
removeAttribute
in interface ServletContext
name
- Name of the context attribute to be removedpublic void setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface ServletContext
name
- Attribute name to be boundvalue
- New attribute value to be boundpublic FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.String filterClass) throws java.lang.IllegalStateException
addFilter
in interface ServletContext
filterName
- Name of filter to addfilterClass
- Name of filter classnull
if the filter has already been fully defined,
else a FilterRegistration.Dynamic
object
that can be used to further configure the filterjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.UnsupportedOperationException
- - if this context was passed to the
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)
method of a ServletContextListener
that was not declared
in web.xml, a web-fragment or annotated with
WebListener
.public FilterRegistration.Dynamic addFilter(java.lang.String filterName, Filter filter) throws java.lang.IllegalStateException
addFilter
in interface ServletContext
filterName
- Name of filter to addfilter
- Filter to addnull
if the filter has already been fully defined,
else a FilterRegistration.Dynamic
object
that can be used to further configure the filterjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.UnsupportedOperationException
- - if this context was passed to the
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)
method of a ServletContextListener
that was not declared
in web.xml, a web-fragment or annotated with
WebListener
.public FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.Class<? extends Filter> filterClass) throws java.lang.IllegalStateException
addFilter
in interface ServletContext
filterName
- Name of filter to addfilterClass
- Class of filter to addnull
if the filter has already been fully defined,
else a FilterRegistration.Dynamic
object
that can be used to further configure the filterjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.UnsupportedOperationException
- - if this context was passed to the
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)
method of a ServletContextListener
that was not declared
in web.xml, a web-fragment or annotated with
WebListener
.public <T extends Filter> T createFilter(java.lang.Class<T> c) throws ServletException
javax.servlet.ServletContext
createFilter
in interface ServletContext
T
- TODOc
- TODOServletException
- TODOpublic FilterRegistration getFilterRegistration(java.lang.String filterName)
javax.servlet.ServletContext
getFilterRegistration
in interface ServletContext
filterName
- TODOpublic ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.String servletClass) throws java.lang.IllegalStateException
addServlet
in interface ServletContext
servletName
- Name of servlet to addservletClass
- Name of servlet classnull
if the servlet has already been fully defined,
else a ServletRegistration.Dynamic
object
that can be used to further configure the servletjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.UnsupportedOperationException
- - if this context was passed to the
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)
method of a ServletContextListener
that was not declared
in web.xml, a web-fragment or annotated with
WebListener
.public ServletRegistration.Dynamic addServlet(java.lang.String servletName, Servlet servlet) throws java.lang.IllegalStateException
addServlet
in interface ServletContext
servletName
- Name of servlet to addservlet
- Servlet instance to addnull
if the servlet has already been fully defined,
else a ServletRegistration.Dynamic
object
that can be used to further configure the servletjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.UnsupportedOperationException
- - if this context was passed to the
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)
method of a ServletContextListener
that was not declared
in web.xml, a web-fragment or annotated with
WebListener
.public ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.Class<? extends Servlet> servletClass) throws java.lang.IllegalStateException
addServlet
in interface ServletContext
servletName
- Name of servlet to addservletClass
- Class of servlet to addnull
if the servlet has already been fully defined,
else a ServletRegistration.Dynamic
object
that can be used to further configure the servletjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.UnsupportedOperationException
- - if this context was passed to the
ServletContextListener.contextInitialized(javax.servlet.ServletContextEvent)
method of a ServletContextListener
that was not declared
in web.xml, a web-fragment or annotated with
WebListener
.public <T extends Servlet> T createServlet(java.lang.Class<T> c) throws ServletException
javax.servlet.ServletContext
createServlet
in interface ServletContext
T
- TODOc
- TODOServletException
- TODOpublic ServletRegistration getServletRegistration(java.lang.String servletName)
javax.servlet.ServletContext
getServletRegistration
in interface ServletContext
servletName
- The name of the Servlet of interestnull
if no Servlet has been registered with the
given namepublic java.util.Set<SessionTrackingMode> getDefaultSessionTrackingModes()
SessionTrackingMode.URL
is always supported, SessionTrackingMode.COOKIE
is supported unless the cookies
attribute has been set to false
for the context and SessionTrackingMode.SSL
is supported if at least one of the connectors
used by this context has the attribute secure
set to
true
.getDefaultSessionTrackingModes
in interface ServletContext
public java.util.Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes
in interface ServletContext
ServletContext.setSessionTrackingModes(Set)
if
one was previously set, else return the defaultspublic SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig
in interface ServletContext
public void setSessionTrackingModes(java.util.Set<SessionTrackingMode> sessionTrackingModes)
javax.servlet.ServletContext
setSessionTrackingModes
in interface ServletContext
sessionTrackingModes
- The session tracking modes to use for this
web applicationjava.lang.IllegalStateException
- if the context has already been initialisedjava.lang.IllegalArgumentException
- If SSL is requested in combination with
anything else or if an unsupported
tracking mode is requestedpublic boolean setInitParameter(java.lang.String name, java.lang.String value)
javax.servlet.ServletContext
setInitParameter
in interface ServletContext
name
- Name of initialisation parametervalue
- Value for initialisation parametertrue
if the call succeeds or false
if
the call fails because an initialisation parameter with the same
name has already been setpublic void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
javax.servlet.ServletContext
addListener
in interface ServletContext
listenerClass
- TODOpublic void addListener(java.lang.String className)
javax.servlet.ServletContext
addListener
in interface ServletContext
className
- TODOpublic <T extends java.util.EventListener> void addListener(T t)
javax.servlet.ServletContext
addListener
in interface ServletContext
T
- TODOt
- TODOpublic <T extends java.util.EventListener> T createListener(java.lang.Class<T> c) throws ServletException
javax.servlet.ServletContext
createListener
in interface ServletContext
T
- TODOc
- TODOServletException
- TODOpublic void declareRoles(java.lang.String... roleNames)
javax.servlet.ServletContext
declareRoles
in interface ServletContext
roleNames
- The roles to addpublic java.lang.ClassLoader getClassLoader()
javax.servlet.ServletContext
getClassLoader
in interface ServletContext
public int getEffectiveMajorVersion()
getEffectiveMajorVersion
in interface ServletContext
public int getEffectiveMinorVersion()
getEffectiveMinorVersion
in interface ServletContext
public java.util.Map<java.lang.String,? extends FilterRegistration> getFilterRegistrations()
getFilterRegistrations
in interface ServletContext
public JspConfigDescriptor getJspConfigDescriptor()
getJspConfigDescriptor
in interface ServletContext
public java.util.Map<java.lang.String,? extends ServletRegistration> getServletRegistrations()
javax.servlet.ServletContext
getServletRegistrations
in interface ServletContext
public java.lang.String getVirtualServerName()
javax.servlet.ServletContext
getVirtualServerName
in interface ServletContext
protected StandardContext getContext()
protected void clearAttributes()
protected ServletContext getFacade()
protected void setNewServletContextListenerAllowed(boolean allowed)
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.