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.
Which XML element is used to declare a filter in a web application's deployment descriptor?
- filter
- filter-mapping
- servlet-filter
- web-filter
The element is used to declare a filter in a web application's deployment descriptor (web.xml). This element contains the filter name and the fully qualified class name of the filter.
How does the servlet container use the order of filter mappings in web.xml?
- Filters are executed based on the order of their registration in the servlet container
- Filters are executed based on the order specified in web.xml
- Filters are executed in alphabetical order
- Filters are executed in random order
The servlet container uses the order of filter mappings in web.xml to determine the sequence in which filters are executed. Filters are executed based on the order specified in web.xml.
Can a filter modify the request and response objects?
- No
- Yes, both request and response objects
- Yes, only request object
- Yes, only response object
Filters have the ability to modify both the request and response objects, allowing them to manipulate data during the processing of a request.
The method __________ is used to set the length of the content body in the response.
- setBodyLength()
- setContentLength()
- setContentSize()
- setResponseLength()
The setContentLength() method is used to set the length of the content body in the response.
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.