Servlet 3.0 programmatic configuration
The configuration methods, addListener, addFilter, and addServlet are introduced in the Servlet 3.0 specification.
The methods for Servlet 3.0 are part of the ServletContext interface. You can call these methods from either a ServletContainerInitializer or a ServletContextListener.
addListener
- Use the following method to add the listener with the given class
name to this servlet context:
void addListener(java.lang.String className)
- Use the following method to add the given listener to this servlet
context:
<T extends java.util.EventListener> void addListener(T t)
- Use the following method to add a listener of the given class
type to this servlet context:
void addListener(java.lang.Class<? extends java.util.EventListener> listenerClass)
- ServletContextAttributeListener
- ServletRequestListener
- ServletRequestAttributeListener
- HttpSessionListener
- HttpSessionAttributeListener
addFilter
- Use the following method to add the filter with the given name
and class type to this servlet context:
addFilter(java.lang.String filterName, java.lang.Class<? extends Filter> filterClass)
- Use the following method to register the given filter instance
with this servlet context under the given filterName:
addFilter(java.lang.String filterName, Filter filter)
- Use the following method to add the filter with the given name
and class name to this servlet context:
addFilter(java.lang.String filterName, java.lang.String className)
addServlet
The addServlet methods dynamically adds servlets to a servletContext. These methods will add the servlet with the given parameters to the web application context. The registered servlet might be further configured using the returned ServletRegistration object.
- Use the following method to add the filter with the given name
and class type to this servlet context:
addFilter(java.lang.String filterName, java.lang.Class<? extends Filter> filterClass)
- Use the following method to register the given filter instance
with this servlet context under the given filterName:
addFilter(java.lang.String filterName, Filter filter)
- Use the following method to add the filter with the given name
and class name to this servlet context:
addFilter(java.lang.String filterName, java.lang.String className)
ServletContainerInitializer
When you configure a JAR file for a shared library and a ServletContainerInitializer is discovered within the JAR, the ServletContainerInitializer is invoked for every application that the shared library associates with.
Deprecated classes in Servlet 3.0
- public void addDynamicServlet(String servletName, String servletClass, String mappingURI, Properties initParameters) throws ServletException, java.lang.SecurityException;
- public void removeDynamicServlet(String servletName) throws java.lang.SecurityException