The __________ method of the FilterChain interface is used to invoke the next filter in the chain.

  • doFilter()
  • invokeNext()
  • nextFilter()
  • proceed()
The doFilter() method of the FilterChain interface is used to invoke the next filter in the chain.

The filter's __________ method is invoked for every request/response pair processed by the filter.

  • doFilter()
  • doProcessing()
  • execute()
  • process()
The filter's doFilter() method is invoked for every request/response pair processed by the filter.

The method __________ is used to handle request and response objects in a filter.

  • doFilter()
  • filterRequest()
  • initFilter()
  • processFilter()
The method doFilter() is used to handle request and response objects in a filter.

Filters are configured in the __________ file of a web application.

  • filter-config.xml
  • filter.xml
  • web-config.xml
  • web.xml
Filters are configured in the web.xml file of a web application.

The __________ method is called by the web container to indicate to a filter that it is being taken out of service.

  • close()
  • destroy()
  • release()
  • terminate()
The destroy() method is called by the web container to indicate to a filter that it is being taken out of service.

If a filter needs to perform different actions based on whether the request is an HTTP GET or POST, where should this logic be implemented?

  • In the destroy() method
  • In the doFilter() method
  • In the init() method
  • In the service() method
The logic for different actions based on HTTP GET or POST requests should be implemented in the doFilter() method of the filter. This method is responsible for processing the request and can be customized for different scenarios.

How would you ensure a filter only processes requests for a specific servlet?

  • Check the servlet name in the configuration
  • Set a specific attribute in the request
  • Use if conditions in the doFilter() method
  • Use the url-pattern in the filter mapping
To ensure a filter processes requests for a specific servlet, configure the filter mapping in the deployment descriptor (web.xml) using the url-pattern element with the appropriate servlet mapping.

What is the primary purpose of a filter chain in a servlet environment?

  • To establish a secure connection
  • To execute servlets sequentially
  • To handle exceptions in a servlet
  • To perform multiple filters on a request and response
The primary purpose of a filter chain is to allow multiple filters to be applied to a request and response in a sequential order, enabling the execution of various processing tasks.

How does a filter pass the request and response to the next entity in the filter chain?

  • Automatically passed by the servlet container
  • By directly calling the next filter
  • By setting a flag in the request
  • Using the chain.doFilter() method
A filter passes the request and response to the next entity in the filter chain using the chain.doFilter() method, which allows the request and response to move to the next filter or servlet in the chain.

Which method is used to initialize a filter in the filter chain?

  • init()
  • initFilter()
  • initialize()
  • initializeFilter()
The init() method is used to initialize a filter in the filter chain. This method is called by the servlet container when the filter is first created.