public class ApplicationContext extends Object implements javax.servlet.ServletContext
ServletContext
that represents
a web application's execution environment. An instance of this class is
associated with each instance of StandardContext
.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 |
---|---|
javax.servlet.FilterRegistration.Dynamic |
addFilter(String filterName,
Class<? extends javax.servlet.Filter> filterClass)
Adds the filter with the given name and class type to this servlet
context.
|
javax.servlet.FilterRegistration.Dynamic |
addFilter(String filterName,
javax.servlet.Filter filter) |
javax.servlet.FilterRegistration.Dynamic |
addFilter(String filterName,
String className)
Adds the filter with the given name and class name to this servlet
context.
|
javax.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> |
addListener(T t)
Adds the given listener to this ServletContext.
|
javax.servlet.ServletRegistration.Dynamic |
addServlet(String servletName,
Class<? extends javax.servlet.Servlet> servletClass) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(String servletName,
javax.servlet.Servlet servlet) |
javax.servlet.ServletRegistration.Dynamic |
addServlet(String servletName,
String className) |
<T extends javax.servlet.Filter> |
createFilter(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> |
createListener(Class<T> clazz)
Instantiates the given EventListener class and performs any
required resource injection into the new EventListener instance
before returning it.
|
<T extends javax.servlet.Servlet> |
createServlet(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 return
null . |
Enumeration<String> |
getAttributeNames()
Return an enumeration of the names of the context attributes
associated with this context.
|
ClassLoader |
getClassLoader() |
javax.servlet.ServletContext |
getContext(String uri)
Return a
ServletContext object that corresponds to a
specified URI on the server. |
String |
getContextPath()
Returns the context path of the web application.
|
Set<javax.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<javax.servlet.SessionTrackingMode> |
getEffectiveSessionTrackingModes()
Gets the session tracking modes that are in effect for this
ServletContext.
|
protected javax.servlet.ServletContext |
getFacade()
Return the facade associated with this ApplicationContext.
|
javax.servlet.FilterRegistration |
getFilterRegistration(String filterName)
Gets the FilterRegistration corresponding to the filter with the
given filterName.
|
Map<String,? extends javax.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, 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.
|
javax.servlet.descriptor.JspConfigDescriptor |
getJspConfigDescriptor()
Gets the
<jsp-config> related configuration
that was aggregated from the web.xml and
web-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, or
null if
the MIME type cannot be determined. |
int |
getMinorVersion()
Return the minor version of the Java Servlet API that we implement.
|
javax.servlet.RequestDispatcher |
getNamedDispatcher(String name)
Return a
RequestDispatcher object that acts as a
wrapper for the named servlet. |
String |
getRealPath(String path) |
String |
getRequestCharacterEncoding() |
javax.servlet.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()
Return the resources object that is mapped to a specified path.
|
String |
getResponseCharacterEncoding() |
String |
getServerInfo()
Return the name and version of the servlet container.
|
javax.servlet.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.
|
javax.servlet.ServletRegistration |
getServletRegistration(String servletName)
Gets the ServletRegistration corresponding to the servlet with the
given servletName.
|
Map<String,? extends javax.servlet.ServletRegistration> |
getServletRegistrations()
Gets a Map of the ServletRegistration objects corresponding to all
currently registered servlets.
|
Enumeration<javax.servlet.Servlet> |
getServlets()
Deprecated.
As of Java Servlet API 2.1, with no direct replacement.
|
javax.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(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) |
void |
setRequestCharacterEncoding(String encoding) |
void |
setResponseCharacterEncoding(String encoding) |
void |
setSessionTimeout(int sessionTimeout) |
void |
setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
Sets the session tracking modes that are to become effective for this
ServletContext.
|
public ApplicationContext(StandardContext context)
context
- The associated Context instancepublic StandardContext getStandardContext()
public DirContext getResources()
public Object getAttribute(String name)
null
.getAttribute
in interface javax.servlet.ServletContext
name
- Name of the context attribute to returnpublic Enumeration<String> getAttributeNames()
getAttributeNames
in interface javax.servlet.ServletContext
public String getContextPath()
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.
getContextPath
in interface javax.servlet.ServletContext
HttpServletRequest.getContextPath()
public javax.servlet.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 javax.servlet.ServletContext
uri
- Absolute URI of a resource on the serverpublic String getInitParameter(String name)
null
if this parameter does not exist.getInitParameter
in interface javax.servlet.ServletContext
name
- Name of the initialization parameter to retrievepublic Enumeration<String> getInitParameterNames()
getInitParameterNames
in interface javax.servlet.ServletContext
public boolean setInitParameter(String name, String value)
setInitParameter
in interface javax.servlet.ServletContext
public int getMajorVersion()
getMajorVersion
in interface javax.servlet.ServletContext
public int getMinorVersion()
getMinorVersion
in interface javax.servlet.ServletContext
public int getEffectiveMajorVersion()
getEffectiveMajorVersion
in interface javax.servlet.ServletContext
public int getEffectiveMinorVersion()
getEffectiveMinorVersion
in interface javax.servlet.ServletContext
public String getMimeType(String file)
null
if
the MIME type cannot be determined.getMimeType
in interface javax.servlet.ServletContext
file
- Filename for which to identify a MIME typepublic javax.servlet.RequestDispatcher getNamedDispatcher(String name)
RequestDispatcher
object that acts as a
wrapper for the named servlet.getNamedDispatcher
in interface javax.servlet.ServletContext
name
- Name of the servlet for which a dispatcher is requestedpublic String getRealPath(String path)
getRealPath
in interface javax.servlet.ServletContext
path
- The virtual path to be translatednull
if the container was unable to perform the
translationpublic javax.servlet.RequestDispatcher getRequestDispatcher(String path)
RequestDispatcher
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.getRequestDispatcher
in interface javax.servlet.ServletContext
path
- The path to the desired resource.public URL getResource(String path) throws MalformedURLException
getResource
in interface javax.servlet.ServletContext
path
- The path to the desired resourceMalformedURLException
- 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 javax.servlet.ServletContext
path
- The path to the desired resource.public Set<String> getResourcePaths(String path)
getResourcePaths
in interface javax.servlet.ServletContext
path
- Collection pathpublic String getServerInfo()
getServerInfo
in interface javax.servlet.ServletContext
public javax.servlet.Servlet getServlet(String name)
getServlet
in interface javax.servlet.ServletContext
public String getServletContextName()
getServletContextName
in interface javax.servlet.ServletContext
public Enumeration<String> getServletNames()
getServletNames
in interface javax.servlet.ServletContext
public Enumeration<javax.servlet.Servlet> getServlets()
getServlets
in interface javax.servlet.ServletContext
public void log(String message)
log
in interface javax.servlet.ServletContext
message
- Message to be writtenpublic void log(Exception exception, String message)
log(String, Throwable)
insteadlog
in interface javax.servlet.ServletContext
exception
- Exception to be reportedmessage
- Message to be writtenpublic void log(String message, Throwable throwable)
log
in interface javax.servlet.ServletContext
message
- Message to be writtenthrowable
- Exception to be reportedpublic void removeAttribute(String name)
removeAttribute
in interface javax.servlet.ServletContext
name
- Name of the context attribute to be removedpublic void setAttribute(String name, Object value)
setAttribute
in interface javax.servlet.ServletContext
name
- Attribute name to be boundvalue
- New attribute value to be boundpublic javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, String className)
addServlet
in interface javax.servlet.ServletContext
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, javax.servlet.Servlet servlet)
addServlet
in interface javax.servlet.ServletContext
public javax.servlet.ServletRegistration.Dynamic addServlet(String servletName, Class<? extends javax.servlet.Servlet> servletClass)
addServlet
in interface javax.servlet.ServletContext
public javax.servlet.ServletRegistration.Dynamic addJspFile(String servletName, String jspFile)
addJspFile
in interface javax.servlet.ServletContext
public <T extends javax.servlet.Servlet> T createServlet(Class<T> clazz) throws javax.servlet.ServletException
createServlet
in interface javax.servlet.ServletContext
javax.servlet.ServletException
public javax.servlet.ServletRegistration getServletRegistration(String servletName)
getServletRegistration
in interface javax.servlet.ServletContext
public Map<String,? extends javax.servlet.ServletRegistration> getServletRegistrations()
getServletRegistrations
in interface javax.servlet.ServletContext
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, String className)
addFilter
in interface javax.servlet.ServletContext
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, javax.servlet.Filter filter)
addFilter
in interface javax.servlet.ServletContext
public javax.servlet.FilterRegistration.Dynamic addFilter(String filterName, Class<? extends javax.servlet.Filter> filterClass)
addFilter
in interface javax.servlet.ServletContext
public <T extends javax.servlet.Filter> T createFilter(Class<T> clazz) throws javax.servlet.ServletException
createFilter
in interface javax.servlet.ServletContext
javax.servlet.ServletException
public javax.servlet.FilterRegistration getFilterRegistration(String filterName)
getFilterRegistration
in interface javax.servlet.ServletContext
public Map<String,? extends javax.servlet.FilterRegistration> getFilterRegistrations()
getFilterRegistrations
in interface javax.servlet.ServletContext
public javax.servlet.SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig
in interface javax.servlet.ServletContext
public void setSessionTrackingModes(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
setSessionTrackingModes
in interface javax.servlet.ServletContext
public Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
getDefaultSessionTrackingModes
in interface javax.servlet.ServletContext
public Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes
in interface javax.servlet.ServletContext
public void addListener(String className)
addListener
in interface javax.servlet.ServletContext
public <T extends EventListener> void addListener(T t)
addListener
in interface javax.servlet.ServletContext
public void addListener(Class<? extends EventListener> listenerClass)
addListener
in interface javax.servlet.ServletContext
public <T extends EventListener> T createListener(Class<T> clazz) throws javax.servlet.ServletException
createListener
in interface javax.servlet.ServletContext
javax.servlet.ServletException
public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
<jsp-config>
related configuration
that was aggregated from the web.xml
and
web-fragment.xml
descriptor files of the web application
represented by this ServletContext.getJspConfigDescriptor
in interface javax.servlet.ServletContext
public ClassLoader getClassLoader()
getClassLoader
in interface javax.servlet.ServletContext
public void declareRoles(String... roleNames)
declareRoles
in interface javax.servlet.ServletContext
public String getVirtualServerName()
getVirtualServerName
in interface javax.servlet.ServletContext
public int getSessionTimeout()
getSessionTimeout
in interface javax.servlet.ServletContext
public void setSessionTimeout(int sessionTimeout)
setSessionTimeout
in interface javax.servlet.ServletContext
public String getRequestCharacterEncoding()
getRequestCharacterEncoding
in interface javax.servlet.ServletContext
public void setRequestCharacterEncoding(String encoding)
setRequestCharacterEncoding
in interface javax.servlet.ServletContext
public String getResponseCharacterEncoding()
getResponseCharacterEncoding
in interface javax.servlet.ServletContext
public void setResponseCharacterEncoding(String encoding)
setResponseCharacterEncoding
in interface javax.servlet.ServletContext
protected javax.servlet.ServletContext getFacade()
Copyright © 2018. All rights reserved.