public class ApplicationContext extends 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 Map<String,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(String filterName,
Class<? extends Filter> filterClass)
Add filter to context.
|
FilterRegistration.Dynamic |
addFilter(String filterName,
Filter filter)
Add filter to context.
|
FilterRegistration.Dynamic |
addFilter(String filterName,
String filterClass)
Add filter to context.
|
void |
addListener(Class<? extends EventListener> listenerClass) |
void |
addListener(String className) |
<T extends EventListener> |
addListener(T t) |
ServletRegistration.Dynamic |
addServlet(String servletName,
Class<? extends Servlet> servletClass)
Add servlet to context.
|
ServletRegistration.Dynamic |
addServlet(String servletName,
Servlet servlet)
Add servlet to context.
|
ServletRegistration.Dynamic |
addServlet(String servletName,
String servletClass)
Add servlet to context.
|
protected void |
clearAttributes()
Clear all application-created attributes.
|
<T extends Filter> |
createFilter(Class<T> c) |
<T extends EventListener> |
createListener(Class<T> c) |
<T extends Servlet> |
createServlet(Class<T> c) |
void |
declareRoles(String... roleNames) |
Object |
getAttribute(String name)
Return the value of the specified context attribute, if any;
otherwise return
null. |
Enumeration<String> |
getAttributeNames()
Return an enumeration of the names of the context attributes
associated with this context.
|
ClassLoader |
getClassLoader() |
protected StandardContext |
getContext() |
ServletContext |
getContext(String uri)
Return a
ServletContext object that corresponds to a
specified URI on the server. |
String |
getContextPath()
Return the main path associated with this context.
|
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() |
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(String filterName) |
Map<String,? extends FilterRegistration> |
getFilterRegistrations() |
String |
getInitParameter(String name)
Return the value of the specified initialization parameter, or
null if this parameter does not exist. |
Enumeration<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.
|
String |
getMimeType(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(String name)
Return a
RequestDispatcher object that acts as a
wrapper for the named servlet. |
protected Map<String,String> |
getReadonlyAttributes()
Deprecated.
|
String |
getRealPath(String path)
Return the real path for a given virtual path, if possible; otherwise
return
null. |
RequestDispatcher |
getRequestDispatcher(String path)
Return a
RequestDispatcher instance that acts as a
wrapper for the resource at the given path. |
URL |
getResource(String path)
Return the URL to the resource that is mapped to a specified path.
|
InputStream |
getResourceAsStream(String path)
Return the requested resource as an
InputStream. |
Set<String> |
getResourcePaths(String path)
Return a Set containing the resource paths of resources member of the
specified collection.
|
DirContext |
getResources()
Deprecated.
|
String |
getServerInfo()
Return the name and version of the servlet container.
|
Servlet |
getServlet(String name)
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
String |
getServletContextName()
Return the display name of this web application.
|
Enumeration<String> |
getServletNames()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
ServletRegistration |
getServletRegistration(String servletName)
Obtain the details of the named servlet.
|
Map<String,? extends ServletRegistration> |
getServletRegistrations() |
Enumeration<Servlet> |
getServlets()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
SessionCookieConfig |
getSessionCookieConfig() |
void |
log(Exception exception,
String message)
Deprecated.
As of Java Servlet API 2.1, use
log(String, Throwable) instead |
void |
log(String message)
Writes the specified message to a servlet log file.
|
void |
log(String message,
Throwable throwable)
Writes the specified message and exception to a servlet log file.
|
void |
removeAttribute(String name)
Remove the context attribute with the specified name, if any.
|
void |
setAttribute(String name,
Object value)
Bind the specified value with the specified context attribute name,
replacing any existing value for that name.
|
boolean |
setInitParameter(String name,
String value) |
protected void |
setNewServletContextListenerAllowed(boolean allowed) |
void |
setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) |
protected static final boolean STRICT_SERVLET_COMPLIANCE
protected static final boolean GET_RESOURCE_REQUIRE_SLASH
public ApplicationContext(StandardContext context)
context - The associated Context instance@Deprecated public DirContext getResources()
public Object getAttribute(String name)
null.getAttribute in interface ServletContextname - 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 Enumeration<String> getAttributeNames()
getAttributeNames in interface ServletContextEnumeration of attribute namesServletContext.getAttribute(java.lang.String)public ServletContext getContext(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 ServletContexturi - 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.RequestDispatcherpublic String getContextPath()
getContextPath in interface ServletContextpublic String getInitParameter(String name)
null if this parameter does not exist.getInitParameter in interface ServletContextname - Name of the initialization parameter to retrieveString containing the value of the initialization
parameterServletConfig.getInitParameter(java.lang.String)public Enumeration<String> getInitParameterNames()
getInitParameterNames in interface ServletContextEnumeration of String objects
containing the names of the context's initialization parametersServletConfig.getInitParameter(java.lang.String)public int getMajorVersion()
getMajorVersion in interface ServletContextpublic int getMinorVersion()
getMinorVersion in interface ServletContextpublic String getMimeType(String file)
null if
the MIME type cannot be determined.getMimeType in interface ServletContextfile - Filename for which to identify a MIME typeString specifying the file's MIME typepublic RequestDispatcher getNamedDispatcher(String name)
RequestDispatcher object that acts as a
wrapper for the named servlet.getNamedDispatcher in interface ServletContextname - 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
RequestDispatcherRequestDispatcher,
ServletContext.getContext(java.lang.String),
ServletConfig.getServletName()public String getRealPath(String path)
null.getRealPath in interface ServletContextpath - The path to the desired resourceString specifying the real path, or null if the
translation cannot be performedpublic RequestDispatcher getRequestDispatcher(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 ServletContextpath - 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
RequestDispatcherRequestDispatcher,
ServletContext.getContext(java.lang.String)public URL getResource(String path) throws MalformedURLException
getResource in interface ServletContextpath - The path to the desired resourcenull if
there is no resource at that pathMalformedURLException - if the path is not given
in the correct formpublic InputStream getResourceAsStream(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 ServletContextpath - The path to the desired resource.InputStream returned to the servlet, or
null if no resource exists at the specified pathpublic Set<String> getResourcePaths(String path)
getResourcePaths in interface ServletContextpath - Collection pathpublic String getServerInfo()
getServerInfo in interface ServletContextString containing at least the servlet container
name and version number@Deprecated public Servlet getServlet(String name)
getServlet in interface ServletContextpublic String getServletContextName()
getServletContextName in interface ServletContext@Deprecated public Enumeration<String> getServletNames()
getServletNames in interface ServletContext@Deprecated public Enumeration<Servlet> getServlets()
getServlets in interface ServletContextpublic void log(String message)
log in interface ServletContextmessage - Message to be written@Deprecated public void log(Exception exception, String message)
log(String, Throwable) insteadlog in interface ServletContextexception - Exception to be reportedmessage - Message to be writtenpublic void log(String message, Throwable throwable)
log in interface ServletContextmessage - Message to be writtenthrowable - Exception to be reportedpublic void removeAttribute(String name)
removeAttribute in interface ServletContextname - Name of the context attribute to be removedpublic void setAttribute(String name, Object value)
setAttribute in interface ServletContextname - Attribute name to be boundvalue - New attribute value to be boundpublic FilterRegistration.Dynamic addFilter(String filterName, String filterClass) throws IllegalStateException
addFilter in interface ServletContextfilterName - 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 filterIllegalStateException - if the context has already been initialisedUnsupportedOperationException - - 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(String filterName, Filter filter) throws IllegalStateException
addFilter in interface ServletContextfilterName - 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 filterIllegalStateException - if the context has already been initialisedUnsupportedOperationException - - 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(String filterName, Class<? extends Filter> filterClass) throws IllegalStateException
addFilter in interface ServletContextfilterName - 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 filterIllegalStateException - if the context has already been initialisedUnsupportedOperationException - - 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(Class<T> c) throws ServletException
createFilter in interface ServletContextServletExceptionpublic FilterRegistration getFilterRegistration(String filterName)
getFilterRegistration in interface ServletContextpublic ServletRegistration.Dynamic addServlet(String servletName, String servletClass) throws IllegalStateException
addServlet in interface ServletContextservletName - 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 servletIllegalStateException - if the context has already been initialisedUnsupportedOperationException - - 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(String servletName, Servlet servlet) throws IllegalStateException
addServlet in interface ServletContextservletName - 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 servletIllegalStateException - if the context has already been initialisedUnsupportedOperationException - - 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(String servletName, Class<? extends Servlet> servletClass) throws IllegalStateException
addServlet in interface ServletContextservletName - 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 servletIllegalStateException - if the context has already been initialisedUnsupportedOperationException - - 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(Class<T> c) throws ServletException
createServlet in interface ServletContextServletExceptionpublic ServletRegistration getServletRegistration(String servletName)
javax.servlet.ServletContextgetServletRegistration in interface ServletContextservletName - The name of the Servlet of interestnull if no Servlet has been registered with the
given namepublic 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 ServletContextpublic Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes in interface ServletContextpublic SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig in interface ServletContextpublic void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)
setSessionTrackingModes in interface ServletContextIllegalStateException - if the context has already been initialisedIllegalArgumentException - If SSL is requested in combination with
anything else or if an unsupported
tracking mode is requestedpublic boolean setInitParameter(String name, String value)
setInitParameter in interface ServletContextpublic void addListener(Class<? extends EventListener> listenerClass)
addListener in interface ServletContextpublic void addListener(String className)
addListener in interface ServletContextpublic <T extends EventListener> void addListener(T t)
addListener in interface ServletContextpublic <T extends EventListener> T createListener(Class<T> c) throws ServletException
createListener in interface ServletContextServletExceptionpublic void declareRoles(String... roleNames)
declareRoles in interface ServletContextpublic ClassLoader getClassLoader()
getClassLoader in interface ServletContextpublic int getEffectiveMajorVersion()
getEffectiveMajorVersion in interface ServletContextpublic int getEffectiveMinorVersion()
getEffectiveMinorVersion in interface ServletContextpublic Map<String,? extends FilterRegistration> getFilterRegistrations()
getFilterRegistrations in interface ServletContextpublic JspConfigDescriptor getJspConfigDescriptor()
getJspConfigDescriptor in interface ServletContextpublic Map<String,? extends ServletRegistration> getServletRegistrations()
getServletRegistrations in interface ServletContextprotected StandardContext getContext()
@Deprecated protected Map<String,String> getReadonlyAttributes()
protected void clearAttributes()
protected ServletContext getFacade()
protected void setNewServletContextListenerAllowed(boolean allowed)
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.