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
ConstructorsConstructorDescriptionJspCServletContext(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.addJspFile(String jspName, String jspFile) Add a JSP to the context.voidaddListener(Class<? extends EventListener> listenerClass) TODO SERVLET3 - Add commentsvoidaddListener(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.voiddeclareRoles(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.intObtain the major version of the servlet specification for which this web application is implemented.intObtain 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.intReturn the Servlet API major version number.getMimeType(String file) Return the MIME type for the specified filename.intReturn 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.Get the default character encoding for reading request bodies.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.Get the default character encoding for writing response bodies.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 replacementintGet the default session timeout.Get the primary name of the virtual host on which this context is deployed.voidDeprecated.Use log(String,Throwable) insteadvoidLog the specified message.voidLog 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 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 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 Details
-
getAttribute
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:
-
getAttributeNames
Return an enumeration of context attribute names.- Specified by:
getAttributeNamesin interfaceServletContext- Returns:
- an
Enumerationof attribute names - See Also:
-
getContext
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:
-
getContextPath
Return the context path.- Specified by:
getContextPathin interfaceServletContext- Returns:
- The main context path
-
getInitParameter
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:
-
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:
-
getMajorVersion
public int getMajorVersion()Return the Servlet API major version number.- Specified by:
getMajorVersionin interfaceServletContext- Returns:
- 4
-
getMimeType
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
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:
-
getRealPath
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
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:
-
getResource
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
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
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
Return descriptive information about this server.- Specified by:
getServerInfoin interfaceServletContext- Returns:
- a
Stringcontaining 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:
getServletin interfaceServletContext- Parameters:
name- Name of the requested servlet- Returns:
- Always
null - Throws:
ServletException- never
-
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.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.This method has been deprecated with no replacementReturn an empty enumeration of servlets.- Specified by:
getServletsin interfaceServletContext- Returns:
- Always and empty Enumeration
-
log
Log the specified message.- Specified by:
login interfaceServletContext- Parameters:
message- The message to be logged
-
log
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
Log the specified message and exception.- Specified by:
login interfaceServletContext- Parameters:
message- The message to be loggedexception- The exception to be logged
-
removeAttribute
Remove the specified context attribute.- Specified by:
removeAttributein interfaceServletContext- Parameters:
name- Name of the attribute to remove
-
setAttribute
Set or replace the specified context attribute.- Specified by:
setAttributein interfaceServletContext- Parameters:
name- Name of the context attribute to setvalue- Corresponding attribute value
-
addFilter
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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
- Specified by:
getSessionCookieConfigin interfaceServletContext- Returns:
- TODO
-
setSessionTrackingModes
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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:javax.servlet.ServletContextAdd servlet to the 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
Description copied from interface:javax.servlet.ServletContextAdd a JSP to the context.- 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
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
getFilterRegistrationin interfaceServletContext- Parameters:
filterName- TODO- Returns:
- TODO
-
getServletRegistration
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
addListenerin interfaceServletContext- Parameters:
listenerClass- TODO
-
addListener
Description copied from interface:javax.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
addListenerin interfaceServletContext- Parameters:
className- TODO
-
addListener
Description copied from interface:javax.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
addListenerin interfaceServletContext- Type Parameters:
T- TODO- Parameters:
t- TODO
-
createListener
Description copied from interface:javax.servlet.ServletContextTODO SERVLET3 - Add comments- Specified by:
createListenerin interfaceServletContext- Type Parameters:
T- TODO- Parameters:
c- TODO- Returns:
- TODO
- Throws:
ServletException- TODO
-
declareRoles
Description copied from interface:javax.servlet.ServletContextAdd to the declared roles for this ServletContext.- Specified by:
declareRolesin interfaceServletContext- Parameters:
roleNames- The roles to add
-
getClassLoader
Description copied from interface:javax.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:javax.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:javax.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
- Specified by:
getFilterRegistrationsin interfaceServletContext- Returns:
- TODO
-
getJspConfigDescriptor
- Specified by:
getJspConfigDescriptorin interfaceServletContext- Returns:
- TODO
-
getServletRegistrations
Description copied from interface:javax.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
Description copied from interface:javax.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:javax.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:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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
Description copied from interface:javax.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
-