The __________ method of a filter is used for initialization.
- filterInit()
- init()
- initFilter()
- initialize()
The init() method of a filter is used for initialization.
Filters can modify the __________ or __________ objects before they reach a servlet.
- request, response
- request, session
- response, context
- session, context
Filters can modify the request or response objects before they reach a servlet.
To pass control to the next entity in the filter chain, a filter must call the _______ method.
- continue()
- doFilter()
- forward()
- next()
To pass control to the next entity in the filter chain, a filter must call the doFilter() method, which allows the request to proceed to the next entity in the chain.
Which of the following is true about ServletConfig?
- It is a configuration object
- It is a servlet class
- It is a servlet interface
- It is used for session management
ServletConfig is an interface that provides a servlet with its initialization parameters. It is used to pass configuration information to the servlet and is not a class or interface related to session management.
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.
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.
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.
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.
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).
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.