When a new attribute is added to the session, which listener interfaces are invoked?
- HttpSessionActivationListener
- HttpSessionAttributeListener
- HttpSessionBindingListener
- HttpSessionEvent
The HttpSessionAttributeListener interface is invoked when a new attribute is added to the session. This allows you to perform actions when attributes are added, removed, or replaced in a session.
Identify the listener interface that would be used to log session creation and destruction.
- HttpSessionActivationListener
- HttpSessionBindingListener
- HttpSessionEvent
- HttpSessionListener
The HttpSessionListener interface is used to log session creation and destruction events. This allows you to perform actions when sessions are created or destroyed in a web application.
In a web application, you need to audit changes to session attributes. Which listener would you implement?
- HttpSessionAttributeListener
- HttpSessionBindingListener
- HttpSessionEvent
- HttpSessionListener
The HttpSessionAttributeListener interface is used to audit changes to session attributes. This allows you to perform actions when attributes are added, removed, or replaced in a session.
What is the purpose of the FilterConfig object in Servlet filters?
- To define filter order.
- To hold configuration parameters for a filter.
- To process HTTP requests.
- To store filter mappings.
The FilterConfig object is used to hold configuration parameters for a filter, allowing the filter to be customized without modifying the filter code itself.
What is the difference between filter chaining and servlet chaining?
- Filter chaining is the process of passing a request through multiple filters
- Filter chaining is the same as servlet chaining
- Servlet chaining involves calling multiple servlets in a sequence
- Servlet chaining is the same as filter chaining
Filter chaining involves passing a request through multiple filters in a defined sequence, allowing each filter to process the request. Servlet chaining, on the other hand, involves calling multiple servlets in a sequence.
How do filters interact with different types of servlets and JSP pages?
- Filters are applied only to static resources
- Filters can be applied to both servlets and JSP pages
- Filters can only be applied to servlets
- Filters cannot be applied to JSP pages
Filters can be applied to both servlets and JSP pages, providing a versatile mechanism for preprocessing and postprocessing of requests and responses in different types of web components.
The __________ object provides the filter with its configuration information.
- FilterConfig
- FilterContext
- ResponseConfig
- ServletRequest
The FilterConfig object provides the filter with its configuration information. It is passed to the init() method of the filter during initialization.
In the deployment descriptor, the __________ tag is used to specify which requests are passed through a particular filter.
In the deployment descriptor, the tag is used to specify which requests are passed through a particular filter by associating it with a filter name and a URL pattern.
To pass the request and response to the next entity in the chain, the filter uses the __________ method.
- chain.continue()
- chain.doFilter()
- chain.doNext()
- chain.forward()
To pass the request and response to the next entity in the chain, the filter uses the chain.doFilter() method. This method is invoked to invoke the next filter or the servlet in the chain.
The sequence of filters applied to a request is determined by the order of _______ in the web.xml file.
- filter
- filter-mapping
- filter-order
- web-filter
The sequence of filters applied to a request is determined by the order of filter-mapping elements in the web.xml file.