Package org.apache.jasper.servlet
Class JspCServletContext
- java.lang.Object
-
- org.apache.jasper.servlet.JspCServletContext
-
- All Implemented Interfaces:
ServletContext
public class JspCServletContext extends Object implements ServletContext
SimpleServletContextimplementation without HTTP-specific methods.- Author:
- Peter Rossbach (pr@webapp.de)
-
-
Field Summary
-
Fields inherited from interface jakarta.servlet.ServletContext
ORDERED_LIBS, TEMPDIR
-
-
Constructor Summary
Constructors Constructor Description JspCServletContext(PrintWriter aLogWriter, URL aResourceBaseURL, ClassLoader classLoader, boolean validate, boolean blockExternal)Create a new instance of this ServletContext implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description FilterRegistration.DynamicaddFilter(String filterName, Filter filter)Add filter to context.FilterRegistration.DynamicaddFilter(String filterName, Class<? extends Filter> filterClass)Add filter to context.FilterRegistration.DynamicaddFilter(String filterName, String className)Add filter to context.ServletRegistration.DynamicaddJspFile(String jspName, String jspFile)voidaddListener(Class<? extends EventListener> listenerClass)TODO SERVLET3 - Add commentsvoidaddListener(String className)TODO SERVLET3 - Add comments<T extends EventListener>
voidaddListener(T t)TODO SERVLET3 - Add commentsServletRegistration.DynamicaddServlet(String servletName, Servlet servlet)Register a servlet instance for use in this ServletContext.ServletRegistration.DynamicaddServlet(String servletName, Class<? extends Servlet> servletClass)Add servlet to context.ServletRegistration.DynamicaddServlet(String servletName, String className)Register a servlet implementation 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.voiddeclareRoles(String... roleNames)Add to the declared roles for this ServletContext.ObjectgetAttribute(String name)Return the specified context attribute, if any.Enumeration<String>getAttributeNames()Return an enumeration of context attribute names.ClassLoadergetClassLoader()Get the web application class loader associated with this ServletContext.ServletContextgetContext(String uripath)Return the servlet context for the specified path.StringgetContextPath()Return the context path.Set<SessionTrackingMode>getDefaultSessionTrackingModes()Obtains the default session tracking modes for this web application.intgetEffectiveMajorVersion()Obtain the major version of the servlet specification for which this web application is implemented.intgetEffectiveMinorVersion()Obtain the minor version of the servlet specification for which this web application is implemented.Set<SessionTrackingMode>getEffectiveSessionTrackingModes()Obtains the currently enabled session tracking modes for this web application.FilterRegistrationgetFilterRegistration(String filterName)TODO SERVLET3 - Add commentsMap<String,? extends FilterRegistration>getFilterRegistrations()StringgetInitParameter(String name)Return the specified context initialization parameter.Enumeration<String>getInitParameterNames()Return an enumeration of the names of context initialization parameters.JspConfigDescriptorgetJspConfigDescriptor()intgetMajorVersion()Return the Servlet API major version number.StringgetMimeType(String file)Return the MIME type for the specified filename.intgetMinorVersion()Return the Servlet API minor version number.RequestDispatchergetNamedDispatcher(String name)Return a request dispatcher for the specified servlet name.StringgetRealPath(String path)Return the real path for the specified context-relative virtual path.StringgetRequestCharacterEncoding()Get the default character encoding for reading request bodies.RequestDispatchergetRequestDispatcher(String path)Return a request dispatcher for the specified context-relative path.URLgetResource(String path)Return a URL object of a resource that is mapped to the specified context-relative path.InputStreamgetResourceAsStream(String path)Return an InputStream allowing access to the resource at the specified context-relative path.Set<String>getResourcePaths(String path)Return the set of resource paths for the "directory" at the specified context path.StringgetResponseCharacterEncoding()Get the default character encoding for writing response bodies.StringgetServerInfo()Return descriptive information about this server.ServletgetServlet(String name)Deprecated.This method has been deprecated with no replacementStringgetServletContextName()Return the name of this servlet context.Enumeration<String>getServletNames()Deprecated.This method has been deprecated with no replacementServletRegistrationgetServletRegistration(String servletName)Obtain the details of the named servlet.Map<String,? extends ServletRegistration>getServletRegistrations()Obtain a Map of servlet names to servlet registrations for all servlets registered with this context.Enumeration<Servlet>getServlets()Deprecated.This method has been deprecated with no replacementSessionCookieConfiggetSessionCookieConfig()intgetSessionTimeout()Get the default session timeout.StringgetVirtualServerName()Get the primary name of the virtual host on which this context is deployed.voidlog(Exception exception, String message)Deprecated.Use log(String,Throwable) insteadvoidlog(String message)Log the specified message.voidlog(String message, Throwable exception)Log the specified message and exception.voidremoveAttribute(String name)Remove the specified context attribute.voidsetAttribute(String name, Object value)Set or replace the specified context attribute.booleansetInitParameter(String name, String value)Set the given initialisation parameter to the given value.voidsetRequestCharacterEncoding(String encoding)Set the default character encoding to use for reading request bodies.voidsetResponseCharacterEncoding(String encoding)Set the default character encoding to use for writing response bodies.voidsetSessionTimeout(int sessionTimeout)Set the default session timeout.voidsetSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)Configures the available session tracking modes for this web application.
-
-
-
Constructor Detail
-
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 thisServletContextvalidate- 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 Detail
-
getAttribute
public Object getAttribute(String name)
Return the specified context attribute, if any.- Specified by:
getAttributein interfaceServletContext- Parameters:
name- Name of the requested attribute- Returns:
- an
Objectcontaining the value of the attribute, ornullif no attribute exists matching the given name - See Also:
ServletContext.getAttributeNames()
-
getAttributeNames
public Enumeration<String> getAttributeNames()
Return an enumeration of context attribute names.- Specified by:
getAttributeNamesin interfaceServletContext- Returns:
- an
Enumerationof attribute names - See Also:
ServletContext.getAttribute(java.lang.String)
-
getContext
public ServletContext getContext(String uripath)
Return the servlet context for the specified path.- Specified by:
getContextin interfaceServletContext- Parameters:
uripath- Server-relative path starting with '/'- Returns:
- the
ServletContextobject that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access. - See Also:
RequestDispatcher
-
getContextPath
public String getContextPath()
Return the context path.- Specified by:
getContextPathin interfaceServletContext- Returns:
- The main context path
-
getInitParameter
public String getInitParameter(String name)
Return the specified context initialization parameter.- Specified by:
getInitParameterin interfaceServletContext- Parameters:
name- Name of the requested parameter- Returns:
- a
Stringcontaining the value of the initialization parameter - See Also:
ServletConfig.getInitParameter(java.lang.String)
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
Return an enumeration of the names of context initialization parameters.- Specified by:
getInitParameterNamesin interfaceServletContext- Returns:
- an
EnumerationofStringobjects containing the names of the context's initialization parameters - See Also:
ServletConfig.getInitParameter(java.lang.String)
-
getMajorVersion
public int getMajorVersion()
Return the Servlet API major version number.- Specified by:
getMajorVersionin interfaceServletContext- Returns:
- 5
-
getMimeType
public String getMimeType(String file)
Return the MIME type for the specified filename.- Specified by:
getMimeTypein interfaceServletContext- Parameters:
file- Filename whose MIME type is requested- Returns:
- a
Stringspecifying the file's MIME type
-
getMinorVersion
public int getMinorVersion()
Return the Servlet API minor version number.- Specified by:
getMinorVersionin interfaceServletContext- Returns:
- 0
-
getNamedDispatcher
public RequestDispatcher getNamedDispatcher(String name)
Return a request dispatcher for the specified servlet name.- Specified by:
getNamedDispatcherin interfaceServletContext- Parameters:
name- Name of the requested servlet- Returns:
- a
RequestDispatcherobject that acts as a wrapper for the named servlet, ornullif theServletContextcannot return aRequestDispatcher - See Also:
RequestDispatcher,ServletContext.getContext(java.lang.String),ServletConfig.getServletName()
-
getRealPath
public String getRealPath(String path)
Return the real path for the specified context-relative virtual path.- Specified by:
getRealPathin interfaceServletContext- Parameters:
path- The context-relative virtual path to resolve- Returns:
- a
Stringspecifying the real path, or null if the translation cannot be performed
-
getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path)
Return a request dispatcher for the specified context-relative path.- Specified by:
getRequestDispatcherin interfaceServletContext- Parameters:
path- Context-relative path for which to acquire a dispatcher- Returns:
- a
RequestDispatcherobject that acts as a wrapper for the resource at the specified path, ornullif theServletContextcannot return aRequestDispatcher - See Also:
RequestDispatcher,ServletContext.getContext(java.lang.String)
-
getResource
public URL getResource(String path) throws MalformedURLException
Return a URL object of a resource that is mapped to the specified context-relative path.- Specified by:
getResourcein interfaceServletContext- Parameters:
path- Context-relative path of the desired resource- Returns:
- the resource located at the named path, or
nullif there is no resource at that path - Throws:
MalformedURLException- if the resource path is not properly formed
-
getResourceAsStream
public InputStream getResourceAsStream(String path)
Return an InputStream allowing access to the resource at the specified context-relative path.- Specified by:
getResourceAsStreamin interfaceServletContext- Parameters:
path- Context-relative path of the desired resource- Returns:
- the
InputStreamreturned to the servlet, ornullif no resource exists at the specified path
-
getResourcePaths
public Set<String> getResourcePaths(String path)
Return the set of resource paths for the "directory" at the specified context path.- Specified by:
getResourcePathsin 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
public String getServerInfo()
Return descriptive information about this server.- Specified by:
getServerInfoin interfaceServletContext- Returns:
- a
Stringcontaining at least the servlet container name and version number
-
getServlet
@Deprecated public Servlet getServlet(String name) throws ServletException
Deprecated.This method has been deprecated with no replacementReturn a null reference for the specified servlet name.- Specified by:
getServletin interfaceServletContext- Parameters:
name- Name of the requested servlet- Returns:
- Always
null - Throws:
ServletException- never
-
getServletContextName
public String getServletContextName()
Return the name of this servlet context.- Specified by:
getServletContextNamein interfaceServletContext- Returns:
- The name of the web application or null if no name has been declared in the deployment descriptor.
-
getServletNames
@Deprecated public Enumeration<String> getServletNames()
Deprecated.This method has been deprecated with no replacementReturn an empty enumeration of servlet names.- Specified by:
getServletNamesin interfaceServletContext- Returns:
- Always and empty Enumeration
-
getServlets
@Deprecated public Enumeration<Servlet> getServlets()
Deprecated.This method has been deprecated with no replacementReturn an empty enumeration of servlets.- Specified by:
getServletsin interfaceServletContext- Returns:
- Always and empty Enumeration
-
log
public void log(String message)
Log the specified message.- Specified by:
login interfaceServletContext- Parameters:
message- The message to be logged
-
log
@Deprecated public void log(Exception exception, String message)
Deprecated.Use log(String,Throwable) insteadLog the specified message and exception.- Specified by:
login interfaceServletContext- Parameters:
exception- The exception to be loggedmessage- The message to be logged
-
log
public void log(String message, Throwable exception)
Log the specified message and exception.- Specified by:
login interfaceServletContext- Parameters:
message- The message to be loggedexception- The exception to be logged
-
removeAttribute
public void removeAttribute(String name)
Remove the specified context attribute.- Specified by:
removeAttributein interfaceServletContext- Parameters:
name- Name of the attribute to remove
-
setAttribute
public void setAttribute(String name, Object value)
Set or replace the specified context attribute.- Specified by:
setAttributein interfaceServletContext- Parameters:
name- Name of the context attribute to setvalue- Corresponding attribute value
-
addFilter
public FilterRegistration.Dynamic addFilter(String filterName, String className)
Description copied from interface:jakarta.servlet.ServletContextAdd filter to context.- Specified by:
addFilterin interfaceServletContext- Parameters:
filterName- Name of filter to addclassName- Name of filter class- Returns:
nullif the filter has already been fully defined, else aFilterRegistration.Dynamicobject that can be used to further configure the filter
-
addServlet
public ServletRegistration.Dynamic addServlet(String servletName, String className)
Description copied from interface:jakarta.servlet.ServletContextRegister a servlet implementation for use in this ServletContext.- Specified by:
addServletin 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
public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
Description copied from interface:jakarta.servlet.ServletContextObtains the default session tracking modes for this web application. By defaultSessionTrackingMode.URLis always supported,SessionTrackingMode.COOKIEis supported unless thecookiesattribute has been set tofalsefor the context andSessionTrackingMode.SSLis supported if at least one of the connectors used by this context has the attributesecureset totrue.- Specified by:
getDefaultSessionTrackingModesin interfaceServletContext- Returns:
- The set of default session tracking modes for this web application
-
getEffectiveSessionTrackingModes
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
Description copied from interface:jakarta.servlet.ServletContextObtains the currently enabled session tracking modes for this web application.- Specified by:
getEffectiveSessionTrackingModesin interfaceServletContext- Returns:
- The value supplied via
ServletContext.setSessionTrackingModes(Set)if one was previously set, else return the defaults
-
getSessionCookieConfig
public SessionCookieConfig getSessionCookieConfig()
- Specified by:
getSessionCookieConfigin interfaceServletContext- Returns:
- TODO
-
setSessionTrackingModes
public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)
Description copied from interface:jakarta.servlet.ServletContextConfigures the available session tracking modes for this web application.- Specified by:
setSessionTrackingModesin interfaceServletContext- Parameters:
sessionTrackingModes- The session tracking modes to use for this web application
-
addFilter
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter)
Description copied from interface:jakarta.servlet.ServletContextAdd filter to context.- Specified by:
addFilterin interfaceServletContext- Parameters:
filterName- Name of filter to addfilter- Filter to add- Returns:
nullif the filter has already been fully defined, else aFilterRegistration.Dynamicobject that can be used to further configure the filter
-
addFilter
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass)
Description copied from interface:jakarta.servlet.ServletContextAdd filter to context.- Specified by:
addFilterin interfaceServletContext- Parameters:
filterName- Name of filter to addfilterClass- Class of filter to add- Returns:
nullif the filter has already been fully defined, else aFilterRegistration.Dynamicobject that can be used to further configure the filter
-
addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet)
Description copied from interface:jakarta.servlet.ServletContextRegister a servlet instance for use in this ServletContext.- Specified by:
addServletin 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:jakarta.servlet.ServletContextAdd servlet to context.- Specified by:
addServletin interfaceServletContext- Parameters:
servletName- Name of servlet to addservletClass- Class of servlet to add- Returns:
nullif the servlet has already been fully defined, else aServletRegistration.Dynamicobject that can be used to further configure the servlet
-
addJspFile
public ServletRegistration.Dynamic addJspFile(String jspName, String jspFile)
- Specified by:
addJspFilein interfaceServletContext- Parameters:
jspName- The servlet name under which this JSP file should be registeredjspFile- The path, relative to the web application root, for the JSP file to be used for this servlet- Returns:
- a
ServletRegistration.Dynamicobject that can be used to further configure the servlet
-
createFilter
public <T extends Filter> T createFilter(Class<T> c) throws ServletException
Description copied from interface:jakarta.servlet.ServletContextCreate a Filter instance using the given class. The instance is just created. No initialisation occurs.- Specified by:
createFilterin 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
public <T extends Servlet> T createServlet(Class<T> c) throws ServletException
Description copied from interface:jakarta.servlet.ServletContextCreate an Servlet instance using the given class. The instance is just created. No initialisation occurs.- Specified by:
createServletin 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
public FilterRegistration getFilterRegistration(String filterName)
Description copied from interface:jakarta.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
getFilterRegistrationin interfaceServletContext- Parameters:
filterName- TODO- Returns:
- TODO
-
getServletRegistration
public ServletRegistration getServletRegistration(String servletName)
Description copied from interface:jakarta.servlet.ServletContextObtain the details of the named servlet.- Specified by:
getServletRegistrationin interfaceServletContext- Parameters:
servletName- The name of the Servlet of interest- Returns:
- The registration details for the named Servlet or
nullif no Servlet has been registered with the given name
-
setInitParameter
public boolean setInitParameter(String name, String value)
Description copied from interface:jakarta.servlet.ServletContextSet the given initialisation parameter to the given value.- Specified by:
setInitParameterin interfaceServletContext- Parameters:
name- Name of initialisation parametervalue- Value for initialisation parameter- Returns:
trueif the call succeeds orfalseif the call fails because an initialisation parameter with the same name has already been set
-
addListener
public void addListener(Class<? extends EventListener> listenerClass)
Description copied from interface:jakarta.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
addListenerin interfaceServletContext- Parameters:
listenerClass- TODO
-
addListener
public void addListener(String className)
Description copied from interface:jakarta.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
addListenerin interfaceServletContext- Parameters:
className- TODO
-
addListener
public <T extends EventListener> void addListener(T t)
Description copied from interface:jakarta.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
addListenerin interfaceServletContext- Type Parameters:
T- TODO- Parameters:
t- TODO
-
createListener
public <T extends EventListener> T createListener(Class<T> c) throws ServletException
Description copied from interface:jakarta.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
createListenerin interfaceServletContext- Type Parameters:
T- TODO- Parameters:
c- TODO- Returns:
- TODO
- Throws:
ServletException- TODO
-
declareRoles
public void declareRoles(String... roleNames)
Description copied from interface:jakarta.servlet.ServletContextAdd to the declared roles for this ServletContext.- Specified by:
declareRolesin interfaceServletContext- Parameters:
roleNames- The roles to add
-
getClassLoader
public ClassLoader getClassLoader()
Description copied from interface:jakarta.servlet.ServletContextGet the web application class loader associated with this ServletContext.- Specified by:
getClassLoaderin interfaceServletContext- Returns:
- The associated web application class loader
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
Description copied from interface:jakarta.servlet.ServletContextObtain the major version of the servlet specification for which this web application is implemented.- Specified by:
getEffectiveMajorVersionin interfaceServletContext- Returns:
- The major version declared in web.xml
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
Description copied from interface:jakarta.servlet.ServletContextObtain the minor version of the servlet specification for which this web application is implemented.- Specified by:
getEffectiveMinorVersionin interfaceServletContext- Returns:
- The minor version declared in web.xml
-
getFilterRegistrations
public Map<String,? extends FilterRegistration> getFilterRegistrations()
- Specified by:
getFilterRegistrationsin interfaceServletContext- Returns:
- TODO
-
getJspConfigDescriptor
public JspConfigDescriptor getJspConfigDescriptor()
- Specified by:
getJspConfigDescriptorin interfaceServletContext- Returns:
- TODO
-
getServletRegistrations
public Map<String,? extends ServletRegistration> getServletRegistrations()
Description copied from interface:jakarta.servlet.ServletContextObtain a Map of servlet names to servlet registrations for all servlets registered with this context.- Specified by:
getServletRegistrationsin interfaceServletContext- Returns:
- A Map of servlet names to servlet registrations for all servlets registered with this context
-
getVirtualServerName
public String getVirtualServerName()
Description copied from interface:jakarta.servlet.ServletContextGet 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:
getVirtualServerNamein interfaceServletContext- Returns:
- The primary name of the virtual host on which this context is deployed
-
getSessionTimeout
public int getSessionTimeout()
Description copied from interface:jakarta.servlet.ServletContextGet the default session timeout.- Specified by:
getSessionTimeoutin interfaceServletContext- Returns:
- The current default session timeout in minutes
-
setSessionTimeout
public void setSessionTimeout(int sessionTimeout)
Description copied from interface:jakarta.servlet.ServletContextSet the default session timeout. This method may only be called before the ServletContext is initialised.- Specified by:
setSessionTimeoutin interfaceServletContext- Parameters:
sessionTimeout- The new default session timeout in minutes.
-
getRequestCharacterEncoding
public String getRequestCharacterEncoding()
Description copied from interface:jakarta.servlet.ServletContextGet the default character encoding for reading request bodies.- Specified by:
getRequestCharacterEncodingin interfaceServletContext- Returns:
- The character encoding name or
nullif no default has been specified
-
setRequestCharacterEncoding
public void setRequestCharacterEncoding(String encoding)
Description copied from interface:jakarta.servlet.ServletContextSet the default character encoding to use for reading request bodies. Calling this method will over-ride any value set in the deployment descriptor.- Specified by:
setRequestCharacterEncodingin interfaceServletContext- Parameters:
encoding- The name of the character encoding to use
-
getResponseCharacterEncoding
public String getResponseCharacterEncoding()
Description copied from interface:jakarta.servlet.ServletContextGet the default character encoding for writing response bodies.- Specified by:
getResponseCharacterEncodingin interfaceServletContext- Returns:
- The character encoding name or
nullif no default has been specified
-
setResponseCharacterEncoding
public void setResponseCharacterEncoding(String encoding)
Description copied from interface:jakarta.servlet.ServletContextSet the default character encoding to use for writing response bodies. Calling this method will over-ride any value set in the deployment descriptor.- Specified by:
setResponseCharacterEncodingin interfaceServletContext- Parameters:
encoding- The name of the character encoding to use
-
-