Package org.apache.jasper.servlet
Class JspCServletContext
java.lang.Object
org.apache.jasper.servlet.JspCServletContext
- All Implemented Interfaces:
ServletContext
Simple
ServletContext
implementation without
HTTP-specific methods.- Author:
- Peter Rossbach (pr@webapp.de)
-
Field Summary
Fields inherited from interface javax.servlet.ServletContext
ORDERED_LIBS, TEMPDIR
-
Constructor Summary
ConstructorDescriptionJspCServletContext
(PrintWriter aLogWriter, URL aResourceBaseURL, ClassLoader classLoader, boolean validate, boolean blockExternal) Create a new instance of this ServletContext implementation. -
Method Summary
Modifier and TypeMethodDescriptionAdd filter to context.Add filter to context.Add filter to context.void
addListener
(Class<? extends EventListener> listenerClass) TODO SERVLET3 - Add commentsvoid
addListener
(String className) TODO SERVLET3 - Add comments<T extends EventListener>
voidaddListener
(T t) TODO SERVLET3 - Add commentsaddServlet
(String servletName, Class<? extends Servlet> servletClass) Add servlet to the context.addServlet
(String servletName, String className) Register a servlet implementation for use in this ServletContext.addServlet
(String servletName, Servlet servlet) Register a servlet instance for use in this ServletContext.<T extends Filter>
TcreateFilter
(Class<T> c) Create a Filter instance using the given class.<T extends EventListener>
TcreateListener
(Class<T> c) TODO SERVLET3 - Add comments<T extends Servlet>
TcreateServlet
(Class<T> c) Create an Servlet instance using the given class.void
declareRoles
(String... roleNames) Add to the declared roles for this ServletContext.getAttribute
(String name) Return the specified context attribute, if any.Return an enumeration of context attribute names.Get the web application class loader associated with this ServletContext.getContext
(String uripath) Return the servlet context for the specified path.Return the context path.Obtains the default session tracking modes for this web application.int
Obtain the major version of the servlet specification for which this web application is implemented.int
Obtain the minor version of the servlet specification for which this web application is implemented.Obtains the currently enabled session tracking modes for this web application.getFilterRegistration
(String filterName) TODO SERVLET3 - Add commentsMap<String,
? extends FilterRegistration> getInitParameter
(String name) Return the specified context initialization parameter.Return an enumeration of the names of context initialization parameters.int
Return the Servlet API major version number.getMimeType
(String file) Return the MIME type for the specified filename.int
Return the Servlet API minor version number.getNamedDispatcher
(String name) Return a request dispatcher for the specified servlet name.getRealPath
(String path) Return the real path for the specified context-relative virtual path.getRequestDispatcher
(String path) Return a request dispatcher for the specified context-relative path.getResource
(String path) Return a URL object of a resource that is mapped to the specified context-relative path.getResourceAsStream
(String path) Return an InputStream allowing access to the resource at the specified context-relative path.getResourcePaths
(String path) Return the set of resource paths for the "directory" at the specified context path.Return descriptive information about this server.getServlet
(String name) Deprecated.This method has been deprecated with no replacementReturn the name of this servlet context.Deprecated.This method has been deprecated with no replacementgetServletRegistration
(String servletName) Obtain the details of the named servlet.Map<String,
? extends ServletRegistration> Obtain a Map of servlet names to servlet registrations for all servlets registered with this context.Deprecated.This method has been deprecated with no replacementGet the primary name of the virtual host on which this context is deployed.void
Deprecated.Use log(String,Throwable) insteadvoid
Log the specified message.void
Log the specified message and exception.void
removeAttribute
(String name) Remove the specified context attribute.void
setAttribute
(String name, Object value) Set or replace the specified context attribute.boolean
setInitParameter
(String name, String value) Set the given initialisation parameter to the given value.void
setSessionTrackingModes
(Set<SessionTrackingMode> sessionTrackingModes) Configures the available session tracking modes for this web application.
-
Constructor Details
-
JspCServletContext
public JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL, ClassLoader classLoader, boolean validate, boolean blockExternal) throws JasperException Create a new instance of this ServletContext implementation.- Parameters:
aLogWriter
- PrintWriter which is used forlog()
callsaResourceBaseURL
- Resource base URLclassLoader
- Class loader for thisServletContext
validate
- Should a validating parser be used to parse web.xml?blockExternal
- Should external entities be blocked when parsing web.xml?- Throws:
JasperException
- An error occurred building the merged web.xml
-
-
Method Details
-
getAttribute
Return the specified context attribute, if any.- Specified by:
getAttribute
in interfaceServletContext
- Parameters:
name
- Name of the requested attribute- Returns:
- an
Object
containing the value of the attribute, ornull
if no attribute exists matching the given name - See Also:
-
getAttributeNames
Return an enumeration of context attribute names.- Specified by:
getAttributeNames
in interfaceServletContext
- Returns:
- an
Enumeration
of attribute names - See Also:
-
getContext
Return the servlet context for the specified path.- Specified by:
getContext
in interfaceServletContext
- Parameters:
uripath
- Server-relative path starting with '/'- Returns:
- the
ServletContext
object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access. - See Also:
-
getContextPath
Return the context path.- Specified by:
getContextPath
in interfaceServletContext
- Returns:
- The main context path
-
getInitParameter
Return the specified context initialization parameter.- Specified by:
getInitParameter
in interfaceServletContext
- Parameters:
name
- Name of the requested parameter- Returns:
- a
String
containing the value of the initialization parameter - See Also:
-
getInitParameterNames
Return an enumeration of the names of context initialization parameters.- Specified by:
getInitParameterNames
in interfaceServletContext
- Returns:
- an
Enumeration
ofString
objects containing the names of the context's initialization parameters - See Also:
-
getMajorVersion
public int getMajorVersion()Return the Servlet API major version number.- Specified by:
getMajorVersion
in interfaceServletContext
- Returns:
- 3
-
getMimeType
Return the MIME type for the specified filename.- Specified by:
getMimeType
in interfaceServletContext
- Parameters:
file
- Filename whose MIME type is requested- Returns:
- a
String
specifying the file's MIME type
-
getMinorVersion
public int getMinorVersion()Return the Servlet API minor version number.- Specified by:
getMinorVersion
in interfaceServletContext
- Returns:
- 1
-
getNamedDispatcher
Return a request dispatcher for the specified servlet name.- Specified by:
getNamedDispatcher
in interfaceServletContext
- Parameters:
name
- Name of the requested servlet- Returns:
- a
RequestDispatcher
object that acts as a wrapper for the named servlet, ornull
if theServletContext
cannot return aRequestDispatcher
- See Also:
-
getRealPath
Return the real path for the specified context-relative virtual path.- Specified by:
getRealPath
in interfaceServletContext
- Parameters:
path
- The context-relative virtual path to resolve- Returns:
- a
String
specifying the real path, or null if the translation cannot be performed
-
getRequestDispatcher
Return a request dispatcher for the specified context-relative path.- Specified by:
getRequestDispatcher
in interfaceServletContext
- Parameters:
path
- Context-relative path for which to acquire a dispatcher- Returns:
- a
RequestDispatcher
object that acts as a wrapper for the resource at the specified path, ornull
if theServletContext
cannot return aRequestDispatcher
- See Also:
-
getResource
Return a URL object of a resource that is mapped to the specified context-relative path.- Specified by:
getResource
in interfaceServletContext
- Parameters:
path
- Context-relative path of the desired resource- Returns:
- the resource located at the named path, or
null
if there is no resource at that path - Throws:
MalformedURLException
- if the resource path is not properly formed
-
getResourceAsStream
Return an InputStream allowing access to the resource at the specified context-relative path.- Specified by:
getResourceAsStream
in interfaceServletContext
- Parameters:
path
- Context-relative path of the desired resource- Returns:
- the
InputStream
returned to the servlet, ornull
if no resource exists at the specified path
-
getResourcePaths
Return the set of resource paths for the "directory" at the specified context path.- Specified by:
getResourcePaths
in interfaceServletContext
- Parameters:
path
- Context-relative base path- Returns:
- a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.
-
getServerInfo
Return descriptive information about this server.- Specified by:
getServerInfo
in interfaceServletContext
- Returns:
- a
String
containing at least the servlet container name and version number
-
getServlet
Deprecated.This method has been deprecated with no replacementReturn a null reference for the specified servlet name.- Specified by:
getServlet
in interfaceServletContext
- Parameters:
name
- Name of the requested servlet- Returns:
- Always
null
- Throws:
ServletException
- never
-
getServletContextName
Return the name of this servlet context.- Specified by:
getServletContextName
in interfaceServletContext
- Returns:
- The name of the web application or null if no name has been declared in the deployment descriptor.
-
getServletNames
Deprecated.This method has been deprecated with no replacementReturn an empty enumeration of servlet names.- Specified by:
getServletNames
in interfaceServletContext
- Returns:
- Always and empty Enumeration
-
getServlets
Deprecated.This method has been deprecated with no replacementReturn an empty enumeration of servlets.- Specified by:
getServlets
in interfaceServletContext
- Returns:
- Always and empty Enumeration
-
log
Log the specified message.- Specified by:
log
in interfaceServletContext
- Parameters:
message
- The message to be logged
-
log
Deprecated.Use log(String,Throwable) insteadLog the specified message and exception.- Specified by:
log
in interfaceServletContext
- Parameters:
exception
- The exception to be loggedmessage
- The message to be logged
-
log
Log the specified message and exception.- Specified by:
log
in interfaceServletContext
- Parameters:
message
- The message to be loggedexception
- The exception to be logged
-
removeAttribute
Remove the specified context attribute.- Specified by:
removeAttribute
in interfaceServletContext
- Parameters:
name
- Name of the attribute to remove
-
setAttribute
Set or replace the specified context attribute.- Specified by:
setAttribute
in interfaceServletContext
- Parameters:
name
- Name of the context attribute to setvalue
- Corresponding attribute value
-
addFilter
Description copied from interface:javax.servlet.ServletContext
Add filter to context.- Specified by:
addFilter
in interfaceServletContext
- Parameters:
filterName
- Name of filter to addclassName
- Name of filter class- Returns:
null
if the filter has already been fully defined, else aFilterRegistration.Dynamic
object that can be used to further configure the filter
-
addServlet
Description copied from interface:javax.servlet.ServletContext
Register a servlet implementation for use in this ServletContext.- Specified by:
addServlet
in interfaceServletContext
- Parameters:
servletName
- The name of the servlet to registerclassName
- The implementation class for the servlet- Returns:
- The registration object that enables further configuration
-
getDefaultSessionTrackingModes
Description copied from interface:javax.servlet.ServletContext
Obtains the default session tracking modes for this web application. By defaultSessionTrackingMode.URL
is always supported,SessionTrackingMode.COOKIE
is supported unless thecookies
attribute has been set tofalse
for the context andSessionTrackingMode.SSL
is supported if at least one of the connectors used by this context has the attributesecure
set totrue
.- Specified by:
getDefaultSessionTrackingModes
in interfaceServletContext
- Returns:
- The set of default session tracking modes for this web application
-
getEffectiveSessionTrackingModes
Description copied from interface:javax.servlet.ServletContext
Obtains the currently enabled session tracking modes for this web application.- Specified by:
getEffectiveSessionTrackingModes
in interfaceServletContext
- Returns:
- The value supplied via
ServletContext.setSessionTrackingModes(Set)
if one was previously set, else return the defaults
-
getSessionCookieConfig
- Specified by:
getSessionCookieConfig
in interfaceServletContext
- Returns:
- TODO
-
setSessionTrackingModes
Description copied from interface:javax.servlet.ServletContext
Configures the available session tracking modes for this web application.- Specified by:
setSessionTrackingModes
in interfaceServletContext
- Parameters:
sessionTrackingModes
- The session tracking modes to use for this web application
-
addFilter
Description copied from interface:javax.servlet.ServletContext
Add filter to context.- Specified by:
addFilter
in interfaceServletContext
- Parameters:
filterName
- Name of filter to addfilter
- Filter to add- Returns:
null
if the filter has already been fully defined, else aFilterRegistration.Dynamic
object that can be used to further configure the filter
-
addFilter
Description copied from interface:javax.servlet.ServletContext
Add filter to context.- Specified by:
addFilter
in interfaceServletContext
- Parameters:
filterName
- Name of filter to addfilterClass
- Class of filter to add- Returns:
null
if the filter has already been fully defined, else aFilterRegistration.Dynamic
object that can be used to further configure the filter
-
addServlet
Description copied from interface:javax.servlet.ServletContext
Register a servlet instance for use in this ServletContext.- Specified by:
addServlet
in interfaceServletContext
- Parameters:
servletName
- The name of the servlet to registerservlet
- The Servlet instance to register- Returns:
- The registration object that enables further configuration
-
addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass) Description copied from interface:javax.servlet.ServletContext
Add servlet to the context.- Specified by:
addServlet
in interfaceServletContext
- Parameters:
servletName
- Name of servlet to addservletClass
- Class of servlet to add- Returns:
null
if the servlet has already been fully defined, else aServletRegistration.Dynamic
object that can be used to further configure the servlet
-
createFilter
Description copied from interface:javax.servlet.ServletContext
Create a Filter instance using the given class. The instance is just created. No initialisation occurs.- Specified by:
createFilter
in interfaceServletContext
- Type Parameters:
T
- The type for the given class- Parameters:
c
- The the class for which an instance should be created- Returns:
- The created Filter instance.
- Throws:
ServletException
- If the Filter instance cannot be created
-
createServlet
Description copied from interface:javax.servlet.ServletContext
Create an Servlet instance using the given class. The instance is just created. No initialisation occurs.- Specified by:
createServlet
in interfaceServletContext
- Type Parameters:
T
- The type for the given class- Parameters:
c
- The the class for which an instance should be created- Returns:
- The created Servlet instance.
- Throws:
ServletException
- If the servlet instance cannot be created.
-
getFilterRegistration
Description copied from interface:javax.servlet.ServletContext
TODO SERVLET3 - Add comments- Specified by:
getFilterRegistration
in interfaceServletContext
- Parameters:
filterName
- TODO- Returns:
- TODO
-
getServletRegistration
Description copied from interface:javax.servlet.ServletContext
Obtain the details of the named servlet.- Specified by:
getServletRegistration
in interfaceServletContext
- Parameters:
servletName
- The name of the Servlet of interest- Returns:
- The registration details for the named Servlet or
null
if no Servlet has been registered with the given name
-
setInitParameter
Description copied from interface:javax.servlet.ServletContext
Set the given initialisation parameter to the given value.- Specified by:
setInitParameter
in interfaceServletContext
- Parameters:
name
- Name of initialisation parametervalue
- Value for initialisation parameter- Returns:
true
if the call succeeds orfalse
if the call fails because an initialisation parameter with the same name has already been set
-
addListener
Description copied from interface:javax.servlet.ServletContext
TODO SERVLET3 - Add comments- Specified by:
addListener
in interfaceServletContext
- Parameters:
listenerClass
- TODO
-
addListener
Description copied from interface:javax.servlet.ServletContext
TODO SERVLET3 - Add comments- Specified by:
addListener
in interfaceServletContext
- Parameters:
className
- TODO
-
addListener
Description copied from interface:javax.servlet.ServletContext
TODO SERVLET3 - Add comments- Specified by:
addListener
in interfaceServletContext
- Type Parameters:
T
- TODO- Parameters:
t
- TODO
-
createListener
Description copied from interface:javax.servlet.ServletContext
TODO SERVLET3 - Add comments- Specified by:
createListener
in interfaceServletContext
- Type Parameters:
T
- TODO- Parameters:
c
- TODO- Returns:
- TODO
- Throws:
ServletException
- TODO
-
declareRoles
Description copied from interface:javax.servlet.ServletContext
Add to the declared roles for this ServletContext.- Specified by:
declareRoles
in interfaceServletContext
- Parameters:
roleNames
- The roles to add
-
getClassLoader
Description copied from interface:javax.servlet.ServletContext
Get the web application class loader associated with this ServletContext.- Specified by:
getClassLoader
in interfaceServletContext
- Returns:
- The associated web application class loader
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()Description copied from interface:javax.servlet.ServletContext
Obtain the major version of the servlet specification for which this web application is implemented.- Specified by:
getEffectiveMajorVersion
in interfaceServletContext
- Returns:
- The major version declared in web.xml
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()Description copied from interface:javax.servlet.ServletContext
Obtain the minor version of the servlet specification for which this web application is implemented.- Specified by:
getEffectiveMinorVersion
in interfaceServletContext
- Returns:
- The minor version declared in web.xml
-
getFilterRegistrations
- Specified by:
getFilterRegistrations
in interfaceServletContext
- Returns:
- TODO
-
getJspConfigDescriptor
- Specified by:
getJspConfigDescriptor
in interfaceServletContext
- Returns:
- TODO
-
getServletRegistrations
Description copied from interface:javax.servlet.ServletContext
Obtain a Map of servlet names to servlet registrations for all servlets registered with this context.- Specified by:
getServletRegistrations
in interfaceServletContext
- Returns:
- A Map of servlet names to servlet registrations for all servlets registered with this context
-
getVirtualServerName
Description copied from interface:javax.servlet.ServletContext
Get the primary name of the virtual host on which this context is deployed. The name may or may not be a valid host name.- Specified by:
getVirtualServerName
in interfaceServletContext
- Returns:
- The primary name of the virtual host on which this context is deployed
-