Package org.apache.catalina.core
Class ApplicationContext
- java.lang.Object
-
- org.apache.catalina.core.ApplicationContext
-
- All Implemented Interfaces:
jakarta.servlet.ServletContext
public class ApplicationContext extends Object implements jakarta.servlet.ServletContext
Standard implementation ofServletContext
that represents a web application's execution environment. An instance of this class is associated with each instance ofStandardContext
.- Version:
- $Revision: 1.15.2.1 $ $Date: 2008/04/17 18:37:06 $
- Author:
- Craig R. McClanahan, Remy Maucherat
-
-
Constructor Summary
Constructors Constructor Description ApplicationContext(StandardContext context)
Construct a new instance of this class, associated with the specified Context instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.servlet.FilterRegistration.Dynamic
addFilter(String filterName, jakarta.servlet.Filter filter)
jakarta.servlet.FilterRegistration.Dynamic
addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass)
Adds the filter with the given name and class type to this servlet context.jakarta.servlet.FilterRegistration.Dynamic
addFilter(String filterName, String className)
Adds the filter with the given name and class name to this servlet context.jakarta.servlet.ServletRegistration.Dynamic
addJspFile(String servletName, String jspFile)
void
addListener(Class<? extends EventListener> listenerClass)
Adds a listener of the given class type to this ServletContext.void
addListener(String className)
Adds the listener with the given class name to this ServletContext.<T extends EventListener>
voidaddListener(T t)
Adds the given listener to this ServletContext.jakarta.servlet.ServletRegistration.Dynamic
addServlet(String servletName, jakarta.servlet.Servlet servlet)
jakarta.servlet.ServletRegistration.Dynamic
addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass)
jakarta.servlet.ServletRegistration.Dynamic
addServlet(String servletName, String className)
<T extends jakarta.servlet.Filter>
TcreateFilter(Class<T> clazz)
Instantiates the given Filter class and performs any required resource injection into the new Filter instance before returning it.<T extends EventListener>
TcreateListener(Class<T> clazz)
Instantiates the given EventListener class and performs any required resource injection into the new EventListener instance before returning it.<T extends jakarta.servlet.Servlet>
TcreateServlet(Class<T> clazz)
Instantiates the given Servlet class and performs any required resource injection into the new Servlet instance before returning it.void
declareRoles(String... roleNames)
Object
getAttribute(String name)
Return the value of the specified context attribute, if any; otherwise returnnull
.Enumeration<String>
getAttributeNames()
Return an enumeration of the names of the context attributes associated with this context.ClassLoader
getClassLoader()
jakarta.servlet.ServletContext
getContext(String uri)
Return aServletContext
object that corresponds to a specified URI on the server.String
getContextPath()
Returns the context path of the web application.Set<jakarta.servlet.SessionTrackingMode>
getDefaultSessionTrackingModes()
Gets the session tracking modes that are supported by default for this ServletContext.int
getEffectiveMajorVersion()
Gets the major version of the Servlet specification that the application represented by this ServletContext is based on.int
getEffectiveMinorVersion()
Gets the minor version of the Servlet specification that the application represented by this ServletContext is based on.Set<jakarta.servlet.SessionTrackingMode>
getEffectiveSessionTrackingModes()
Gets the session tracking modes that are in effect for this ServletContext.protected jakarta.servlet.ServletContext
getFacade()
Return the facade associated with this ApplicationContext.jakarta.servlet.FilterRegistration
getFilterRegistration(String filterName)
Gets the FilterRegistration corresponding to the filter with the given filterName.Map<String,? extends jakarta.servlet.FilterRegistration>
getFilterRegistrations()
Gets a Map of the FilterRegistration objects corresponding to all currently registered filters.String
getInitParameter(String name)
Return the value of the specified initialization parameter, ornull
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.jakarta.servlet.descriptor.JspConfigDescriptor
getJspConfigDescriptor()
Gets the<jsp-config>
related configuration that was aggregated from theweb.xml
andweb-fragment.xml
descriptor files of the web application represented by this ServletContext.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, ornull
if the MIME type cannot be determined.int
getMinorVersion()
Return the minor version of the Java Servlet API that we implement.jakarta.servlet.RequestDispatcher
getNamedDispatcher(String name)
Return aRequestDispatcher
object that acts as a wrapper for the named servlet.String
getRealPath(String path)
String
getRequestCharacterEncoding()
jakarta.servlet.RequestDispatcher
getRequestDispatcher(String path)
Return aRequestDispatcher
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 anInputStream
.Set<String>
getResourcePaths(String path)
Return a Set containing the resource paths of resources member of the specified collection.DirContext
getResources()
Return the resources object that is mapped to a specified path.String
getResponseCharacterEncoding()
String
getServerInfo()
Return the name and version of the servlet container.String
getServletContextName()
Return the display name of this web application.jakarta.servlet.ServletRegistration
getServletRegistration(String servletName)
Gets the ServletRegistration corresponding to the servlet with the given servletName.Map<String,? extends jakarta.servlet.ServletRegistration>
getServletRegistrations()
Gets a Map of the ServletRegistration objects corresponding to all currently registered servlets.jakarta.servlet.SessionCookieConfig
getSessionCookieConfig()
Gets the SessionCookieConfig object through which various properties of the session tracking cookies created on behalf of this ServletContext may be configured.int
getSessionTimeout()
StandardContext
getStandardContext()
String
getVirtualServerName()
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)
void
setRequestCharacterEncoding(String encoding)
void
setResponseCharacterEncoding(String encoding)
void
setSessionTimeout(int sessionTimeout)
void
setSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes)
Sets the session tracking modes that are to become effective for this ServletContext.
-
-
-
Constructor Detail
-
ApplicationContext
public ApplicationContext(StandardContext context)
Construct a new instance of this class, associated with the specified Context instance.- Parameters:
context
- The associated Context instance
-
-
Method Detail
-
getStandardContext
public StandardContext getStandardContext()
-
getResources
public DirContext getResources()
Return the resources object that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.
-
getAttribute
public Object getAttribute(String name)
Return the value of the specified context attribute, if any; otherwise returnnull
.- Specified by:
getAttribute
in interfacejakarta.servlet.ServletContext
- Parameters:
name
- Name of the context attribute to return
-
getAttributeNames
public Enumeration<String> getAttributeNames()
Return an enumeration of the names of the context attributes associated with this context.- Specified by:
getAttributeNames
in interfacejakarta.servlet.ServletContext
-
getContextPath
public String getContextPath()
Returns the context path of the web application.The context path is the portion of the request URI that is used to select the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".
It is possible that a servlet container may match a context by more than one context path. In such cases the
HttpServletRequest.getContextPath()
will return the actual context path used by the request and it may differ from the path returned by this method. The context path returned by this method should be considered as the prime or preferred context path of the application.- Specified by:
getContextPath
in interfacejakarta.servlet.ServletContext
- See Also:
HttpServletRequest.getContextPath()
-
getContext
public jakarta.servlet.ServletContext getContext(String uri)
Return aServletContext
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 obtainRequestDispatcher
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.- Specified by:
getContext
in interfacejakarta.servlet.ServletContext
- Parameters:
uri
- Absolute URI of a resource on the server
-
getInitParameter
public String getInitParameter(String name)
Return the value of the specified initialization parameter, ornull
if this parameter does not exist.- Specified by:
getInitParameter
in interfacejakarta.servlet.ServletContext
- Parameters:
name
- Name of the initialization parameter to retrieve
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
Return the names of the context's initialization parameters, or an empty enumeration if the context has no initialization parameters.- Specified by:
getInitParameterNames
in interfacejakarta.servlet.ServletContext
-
setInitParameter
public boolean setInitParameter(String name, String value)
- Specified by:
setInitParameter
in interfacejakarta.servlet.ServletContext
- Returns:
- true if the context initialization parameter with the given name and value was set successfully on this ServletContext, and false if it was not set because this ServletContext already contains a context initialization parameter with a matching name
-
getMajorVersion
public int getMajorVersion()
Return the major version of the Java Servlet API that we implement.- Specified by:
getMajorVersion
in interfacejakarta.servlet.ServletContext
-
getMinorVersion
public int getMinorVersion()
Return the minor version of the Java Servlet API that we implement.- Specified by:
getMinorVersion
in interfacejakarta.servlet.ServletContext
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
Gets the major version of the Servlet specification that the application represented by this ServletContext is based on.- Specified by:
getEffectiveMajorVersion
in interfacejakarta.servlet.ServletContext
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
Gets the minor version of the Servlet specification that the application represented by this ServletContext is based on.- Specified by:
getEffectiveMinorVersion
in interfacejakarta.servlet.ServletContext
-
getMimeType
public String getMimeType(String file)
Return the MIME type of the specified file, ornull
if the MIME type cannot be determined.- Specified by:
getMimeType
in interfacejakarta.servlet.ServletContext
- Parameters:
file
- Filename for which to identify a MIME type
-
getNamedDispatcher
public jakarta.servlet.RequestDispatcher getNamedDispatcher(String name)
Return aRequestDispatcher
object that acts as a wrapper for the named servlet.- Specified by:
getNamedDispatcher
in interfacejakarta.servlet.ServletContext
- Parameters:
name
- Name of the servlet for which a dispatcher is requested
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPath
in interfacejakarta.servlet.ServletContext
- Parameters:
path
- The virtual path to be translated- Returns:
- the real path corresponding to the given virtual path, or
null
if the container was unable to perform the translation
-
getRequestDispatcher
public jakarta.servlet.RequestDispatcher getRequestDispatcher(String path)
Return aRequestDispatcher
instance that acts as a wrapper for the resource at the given path. The path must begin with a "/" or be empty, and is interpreted as relative to the current context root.- Specified by:
getRequestDispatcher
in interfacejakarta.servlet.ServletContext
- Parameters:
path
- The path to the desired resource.
-
getResource
public URL getResource(String path) throws MalformedURLException
Return the URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.- Specified by:
getResource
in interfacejakarta.servlet.ServletContext
- Parameters:
path
- The path to the desired resource- Throws:
MalformedURLException
- if the path is not given in the correct form
-
getResourceAsStream
public InputStream getResourceAsStream(String path)
Return the requested resource as anInputStream
. The path must be specified according to the rules described undergetResource
. If no such resource can be identified, returnnull
.- Specified by:
getResourceAsStream
in interfacejakarta.servlet.ServletContext
- Parameters:
path
- The path to the desired resource.
-
getResourcePaths
public Set<String> getResourcePaths(String path)
Return a Set containing the resource paths of resources member of the specified collection. Each path will be a String starting with a "/" character. The returned set is immutable.- Specified by:
getResourcePaths
in interfacejakarta.servlet.ServletContext
- Parameters:
path
- Collection path
-
getServerInfo
public String getServerInfo()
Return the name and version of the servlet container.- Specified by:
getServerInfo
in interfacejakarta.servlet.ServletContext
-
getServletContextName
public String getServletContextName()
Return the display name of this web application.- Specified by:
getServletContextName
in interfacejakarta.servlet.ServletContext
-
log
public void log(String message)
Writes the specified message to a servlet log file.- Specified by:
log
in interfacejakarta.servlet.ServletContext
- Parameters:
message
- Message to be written
-
log
public void log(String message, Throwable throwable)
Writes the specified message and exception to a servlet log file.- Specified by:
log
in interfacejakarta.servlet.ServletContext
- Parameters:
message
- Message to be writtenthrowable
- Exception to be reported
-
removeAttribute
public void removeAttribute(String name)
Remove the context attribute with the specified name, if any.- Specified by:
removeAttribute
in interfacejakarta.servlet.ServletContext
- Parameters:
name
- Name of the context attribute to be removed
-
setAttribute
public void setAttribute(String name, Object value)
Bind the specified value with the specified context attribute name, replacing any existing value for that name.- Specified by:
setAttribute
in interfacejakarta.servlet.ServletContext
- Parameters:
name
- Attribute name to be boundvalue
- New attribute value to be bound
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
- Specified by:
addServlet
in interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, jakarta.servlet.Servlet servlet)
- Specified by:
addServlet
in interfacejakarta.servlet.ServletContext
-
addServlet
public jakarta.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends jakarta.servlet.Servlet> servletClass)
- Specified by:
addServlet
in interfacejakarta.servlet.ServletContext
-
addJspFile
public jakarta.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
- Specified by:
addJspFile
in interfacejakarta.servlet.ServletContext
-
createServlet
public <T extends jakarta.servlet.Servlet> T createServlet(Class<T> clazz) throws jakarta.servlet.ServletException
Instantiates the given Servlet class and performs any required resource injection into the new Servlet instance before returning it.- Specified by:
createServlet
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getServletRegistration
public jakarta.servlet.ServletRegistration getServletRegistration(String servletName)
Gets the ServletRegistration corresponding to the servlet with the given servletName.- Specified by:
getServletRegistration
in interfacejakarta.servlet.ServletContext
-
getServletRegistrations
public Map<String,? extends jakarta.servlet.ServletRegistration> getServletRegistrations()
Gets a Map of the ServletRegistration objects corresponding to all currently registered servlets.- Specified by:
getServletRegistrations
in interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
Adds the filter with the given name and class name to this servlet context.- Specified by:
addFilter
in interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, jakarta.servlet.Filter filter)
- Specified by:
addFilter
in interfacejakarta.servlet.ServletContext
-
addFilter
public jakarta.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends jakarta.servlet.Filter> filterClass)
Adds the filter with the given name and class type to this servlet context.- Specified by:
addFilter
in interfacejakarta.servlet.ServletContext
-
createFilter
public <T extends jakarta.servlet.Filter> T createFilter(Class<T> clazz) throws jakarta.servlet.ServletException
Instantiates the given Filter class and performs any required resource injection into the new Filter instance before returning it.- Specified by:
createFilter
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getFilterRegistration
public jakarta.servlet.FilterRegistration getFilterRegistration(String filterName)
Gets the FilterRegistration corresponding to the filter with the given filterName.- Specified by:
getFilterRegistration
in interfacejakarta.servlet.ServletContext
-
getFilterRegistrations
public Map<String,? extends jakarta.servlet.FilterRegistration> getFilterRegistrations()
Gets a Map of the FilterRegistration objects corresponding to all currently registered filters.- Specified by:
getFilterRegistrations
in interfacejakarta.servlet.ServletContext
-
getSessionCookieConfig
public jakarta.servlet.SessionCookieConfig getSessionCookieConfig()
Gets the SessionCookieConfig object through which various properties of the session tracking cookies created on behalf of this ServletContext may be configured.- Specified by:
getSessionCookieConfig
in interfacejakarta.servlet.ServletContext
-
setSessionTrackingModes
public void setSessionTrackingModes(Set<jakarta.servlet.SessionTrackingMode> sessionTrackingModes)
Sets the session tracking modes that are to become effective for this ServletContext.- Specified by:
setSessionTrackingModes
in interfacejakarta.servlet.ServletContext
-
getDefaultSessionTrackingModes
public Set<jakarta.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
Gets the session tracking modes that are supported by default for this ServletContext.- Specified by:
getDefaultSessionTrackingModes
in interfacejakarta.servlet.ServletContext
- Returns:
- set of the session tracking modes supported by default for this ServletContext
-
getEffectiveSessionTrackingModes
public Set<jakarta.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
Gets the session tracking modes that are in effect for this ServletContext.- Specified by:
getEffectiveSessionTrackingModes
in interfacejakarta.servlet.ServletContext
- Returns:
- set of the session tracking modes in effect for this ServletContext
-
addListener
public void addListener(String className)
Adds the listener with the given class name to this ServletContext.- Specified by:
addListener
in interfacejakarta.servlet.ServletContext
-
addListener
public <T extends EventListener> void addListener(T t)
Adds the given listener to this ServletContext.- Specified by:
addListener
in interfacejakarta.servlet.ServletContext
-
addListener
public void addListener(Class<? extends EventListener> listenerClass)
Adds a listener of the given class type to this ServletContext.- Specified by:
addListener
in interfacejakarta.servlet.ServletContext
-
createListener
public <T extends EventListener> T createListener(Class<T> clazz) throws jakarta.servlet.ServletException
Instantiates the given EventListener class and performs any required resource injection into the new EventListener instance before returning it.- Specified by:
createListener
in interfacejakarta.servlet.ServletContext
- Throws:
jakarta.servlet.ServletException
-
getJspConfigDescriptor
public jakarta.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
Gets the<jsp-config>
related configuration that was aggregated from theweb.xml
andweb-fragment.xml
descriptor files of the web application represented by this ServletContext.- Specified by:
getJspConfigDescriptor
in interfacejakarta.servlet.ServletContext
-
getClassLoader
public ClassLoader getClassLoader()
- Specified by:
getClassLoader
in interfacejakarta.servlet.ServletContext
-
declareRoles
public void declareRoles(String... roleNames)
- Specified by:
declareRoles
in interfacejakarta.servlet.ServletContext
-
getVirtualServerName
public String getVirtualServerName()
- Specified by:
getVirtualServerName
in interfacejakarta.servlet.ServletContext
-
getSessionTimeout
public int getSessionTimeout()
- Specified by:
getSessionTimeout
in interfacejakarta.servlet.ServletContext
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout)
- Specified by:
setSessionTimeout
in interfacejakarta.servlet.ServletContext
-
getRequestCharacterEncoding
public String getRequestCharacterEncoding()
- Specified by:
getRequestCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
setRequestCharacterEncoding
public void setRequestCharacterEncoding(String encoding)
- Specified by:
setRequestCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
getResponseCharacterEncoding
public String getResponseCharacterEncoding()
- Specified by:
getResponseCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
setResponseCharacterEncoding
public void setResponseCharacterEncoding(String encoding)
- Specified by:
setResponseCharacterEncoding
in interfacejakarta.servlet.ServletContext
-
getFacade
protected jakarta.servlet.ServletContext getFacade()
Return the facade associated with this ApplicationContext.
-
-