public class ApplicationContext
extends java.lang.Object
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 |
attributes
The context attributes for this context.
|
Constructor and Description |
---|
ApplicationContext(java.lang.String basePath,
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) |
FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
Filter filter) |
FilterRegistration.Dynamic |
addFilter(java.lang.String filterName,
java.lang.String className) |
void |
addListener(java.lang.Class<? extends java.util.EventListener> listenerClass) |
void |
addListener(java.lang.String className) |
<T extends java.util.EventListener> |
addListener(T listener) |
ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
java.lang.Class<? extends Servlet> clazz) |
ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
Servlet servlet) |
ServletRegistration.Dynamic |
addServlet(java.lang.String servletName,
java.lang.String className) |
protected void |
checkListenerType(java.util.EventListener listener) |
protected void |
clearAttributes()
Clear all application-created attributes.
|
<T extends Filter> |
createFilter(java.lang.Class<T> c) |
<T extends java.util.EventListener> |
createListener(java.lang.Class<T> clazz) |
<T extends Servlet> |
createServlet(java.lang.Class<T> c) |
void |
declareRoles(java.lang.String... roleNames) |
java.lang.Object |
getAttribute(java.lang.String name)
Return the value of the specified context attribute, if any;
otherwise return
null . |
java.util.Enumeration |
getAttributeNames()
Return an enumeration of the names of the context attributes
associated with this context.
|
java.lang.ClassLoader |
getClassLoader() |
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() |
int |
getEffectiveMajorVersion() |
int |
getEffectiveMinorVersion() |
java.util.Set<SessionTrackingMode> |
getEffectiveSessionTrackingModes() |
protected ServletContext |
getFacade()
Return the facade associated with this ApplicationContext.
|
FilterRegistration |
getFilterRegistration(java.lang.String filterName) |
java.util.Map<java.lang.String,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 |
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. |
protected java.util.Map |
getReadonlyAttributes() |
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 |
getResourcePaths(java.lang.String path)
Return a Set containing the resource paths of resources member of the
specified collection.
|
javax.naming.directory.DirContext |
getResources()
Return the resources object that is mapped to a specified path.
|
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 |
getServletNames()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
ServletRegistration |
getServletRegistration(java.lang.String servletName) |
java.util.Map<java.lang.String,ServletRegistration> |
getServletRegistrations() |
java.util.Enumeration |
getServlets()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
SessionCookieConfig |
getSessionCookieConfig() |
boolean |
isRestricted() |
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) |
void |
setRestricted(boolean restricted) |
void |
setSessionTrackingModes(java.util.Set<SessionTrackingMode> sessionTrackingModes) |
public ApplicationContext(java.lang.String basePath, StandardContext context)
context
- The associated Context instancepublic javax.naming.directory.DirContext getResources()
public boolean isRestricted()
public void setRestricted(boolean restricted)
public java.lang.Object getAttribute(java.lang.String name)
null
.name
- Name of the context attribute to returnpublic java.util.Enumeration getAttributeNames()
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.uri
- Absolute URI of a resource on the serverpublic java.lang.String getContextPath()
public java.lang.String getInitParameter(java.lang.String name)
null
if this parameter does not exist.name
- Name of the initialization parameter to retrievepublic java.util.Enumeration getInitParameterNames()
public int getMajorVersion()
public int getMinorVersion()
public java.lang.String getMimeType(java.lang.String file)
null
if
the MIME type cannot be determined.file
- Filename for which to identify a MIME typepublic RequestDispatcher getNamedDispatcher(java.lang.String name)
RequestDispatcher
object that acts as a
wrapper for the named servlet.name
- Name of the servlet for which a dispatcher is requestedpublic java.lang.String getRealPath(java.lang.String path)
null
.path
- The path to the desired resourcepublic 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.path
- The path to the desired resource.public java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException
path
- The path to the desired resourcejava.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
.path
- The path to the desired resource.public java.util.Set getResourcePaths(java.lang.String path)
path
- Collection pathpublic java.lang.String getServerInfo()
public Servlet getServlet(java.lang.String name)
public java.lang.String getServletContextName()
public java.util.Enumeration getServletNames()
public java.util.Enumeration getServlets()
public void log(java.lang.String message)
message
- Message to be writtenpublic void log(java.lang.Exception exception, java.lang.String message)
log(String, Throwable)
insteadexception
- Exception to be reportedmessage
- Message to be writtenpublic void log(java.lang.String message, java.lang.Throwable throwable)
message
- Message to be writtenthrowable
- Exception to be reportedpublic void removeAttribute(java.lang.String name)
name
- Name of the context attribute to be removedpublic void setAttribute(java.lang.String name, java.lang.Object value)
name
- Attribute name to be boundvalue
- New attribute value to be boundpublic FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.String className) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.IllegalStateException
public FilterRegistration.Dynamic addFilter(java.lang.String filterName, Filter filter)
public FilterRegistration.Dynamic addFilter(java.lang.String filterName, java.lang.Class<? extends Filter> filterClass)
public ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.String className) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.IllegalStateException
public ServletRegistration.Dynamic addServlet(java.lang.String servletName, java.lang.Class<? extends Servlet> clazz) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException
java.lang.IllegalArgumentException
java.lang.IllegalStateException
public ServletRegistration.Dynamic addServlet(java.lang.String servletName, Servlet servlet)
public FilterRegistration getFilterRegistration(java.lang.String filterName)
public ServletRegistration getServletRegistration(java.lang.String servletName)
public java.util.Map<java.lang.String,FilterRegistration> getFilterRegistrations()
public java.util.Map<java.lang.String,ServletRegistration> getServletRegistrations()
public java.util.Set<SessionTrackingMode> getDefaultSessionTrackingModes()
public java.util.Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
public SessionCookieConfig getSessionCookieConfig()
public <T extends Filter> T createFilter(java.lang.Class<T> c) throws ServletException
ServletException
public <T extends Servlet> T createServlet(java.lang.Class<T> c) throws ServletException
ServletException
public boolean setInitParameter(java.lang.String name, java.lang.String value)
public void setSessionTrackingModes(java.util.Set<SessionTrackingMode> sessionTrackingModes)
public void addListener(java.lang.String className)
public <T extends java.util.EventListener> void addListener(T listener)
public void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
public <T extends java.util.EventListener> T createListener(java.lang.Class<T> clazz) throws ServletException
ServletException
public java.lang.ClassLoader getClassLoader()
public JspConfigDescriptor getJspConfigDescriptor()
public int getEffectiveMajorVersion()
public int getEffectiveMinorVersion()
public void declareRoles(java.lang.String... roleNames)
protected void checkListenerType(java.util.EventListener listener)
protected StandardContext getContext()
protected java.util.Map getReadonlyAttributes()
protected void clearAttributes()
protected ServletContext getFacade()