How do filters interact with the rest of the servlet processing pipeline?
- Filters can modify both request and response
- Filters can modify only the request
- Filters can modify only the response
- Filters have no interaction with the servlet processing pipeline
Filters in a servlet container can interact with both the request and response objects in the servlet processing pipeline. This enables them to modify the incoming request before it reaches the servlet and manipulate the outgoing response after the servlet has processed the request.
What is the scope of servlet initialization parameters?
- Application scope
- Page scope
- Request scope
- Session scope
Servlet initialization parameters have application scope, meaning they are accessible throughout the entire application.
How can filters be used to manage cross-cutting concerns in a web application?
- Filters are applied only to static resources
- Filters are not suitable for managing cross-cutting concerns
- Filters are used to manage request and response modifications
- Filters can only be applied to servlets
Filters are commonly used in web applications to manage cross-cutting concerns by allowing the modification of both request and response objects before they reach the servlet or after the servlet has processed them.
Which listener interface is used to receive notifications about changes to the servlet request?
- HttpSessionAttributeListener
- HttpSessionBindingListener
- ServletContextListener
- ServletRequestListener
The ServletRequestListener interface is used to receive notifications about changes to the servlet request.
Which listener interface is implemented to track session creation and destruction?
- HttpSessionListener
- ServletContextAttributeListener
- ServletContextListener
- ServletRequestListener
The HttpSessionListener interface is implemented to track session creation and destruction events in servlets.
What type of listener is used to monitor changes in ServletContext attributes?
- HttpSessionAttributeListener
- HttpSessionListener
- ServletContextAttributeListener
- ServletRequestListener
The ServletContextAttributeListener is used to monitor changes in ServletContext attributes.
Which method is used to get a reference to the ServletContext?
- getContext()
- getServletConfig()
- getServletContext()
- init()
The getServletContext() method is used to obtain a reference to the ServletContext. It is typically called within a servlet using the this.getServletContext() or getServletContext() to access the context information.
How should filters be configured to apply only to certain URL patterns in a web application?
- Configure in the web.xml file
- Filters automatically apply to all URLs
- Specify URL patterns in the filter mapping in the deployment descriptor
- Use annotations in the filter class
Filters should be configured to apply only to certain URL patterns by specifying those patterns in the filter mapping in the deployment descriptor (web.xml).
If a filter needs to modify the response header of all responses, which method should be primarily used?
- doFilter()
- doResponse()
- init()
- modifyHeader()
To modify the response header of all responses, the filter should primarily use the doFilter() method, where manipulation of both request and response is possible.
A filter is implemented to log request details. Where should this logging take place in the filter's methods?
- destroy()
- doFilter()
- filterConfig()
- init()
The logging of request details in a filter should take place within the doFilter() method, which is called for each request and allows processing of the request and response.
For security purposes, filters are often used to implement __________ and __________ controls.
- authentication, authorization
- authentication, validation
- authorization, authentication
- validation, authorization
For security purposes, filters are often used to implement authentication and authorization controls, ensuring proper user identification and access rights in a web application.
Filters can be applied to __________ or __________ resources in a web application.
- dynamic, JSP
- servlets, dynamic
- servlets, static
- static, dynamic
Filters can be applied to both servlets and static resources or servlets and dynamic resources in a web application.