At which point in the request processing are filters applied in a web application?

  • After the response is generated by the servlet
  • At the end of the servlet lifecycle
  • Before the request reaches the servlet
  • During servlet initialization
Filters are applied before the request reaches the servlet, allowing for pre-processing of the request or post-processing of the response.

Which interface must a class implement to act as a filter in a web application?

  • Filter
  • HttpFilter
  • Servlet
  • WebFilter
To act as a filter in a web application, a class must implement the Filter interface.

What is the correct order of method calls in the lifecycle of a filter?

  • destroy(), init(), doFilter()
  • doFilter(), init(), destroy()
  • init(), destroy(), doFilter()
  • init(), doFilter(), destroy()
The correct order of method calls in the lifecycle of a filter is init(), doFilter(), destroy(). Filters are initialized first, then the doFilter() method is called for each request, and finally, the destroy() method is called when the filter is removed from service.

How can filters dynamically modify the request and response in a servlet-based application?

  • Using the alter() method
  • Using the doFilter() method
  • Using the modify() method
  • Using the transform() method
Filters can dynamically modify the request and response by implementing the doFilter() method. This method provides access to the request and response objects, allowing for manipulation before and after the request reaches the servlet.

In what scenario would a filter be used instead of a servlet?

  • For authentication and logging
  • For handling HTTP requests
  • For managing session state
  • For processing business logic
Filters are typically used for tasks such as authentication, logging, and modifying the request and response. In scenarios where the primary purpose is not to generate a response, but to perform pre or post-processing, filters are preferred over servlets.

A filter is configured in the web application's __________ file.

  • config.xml
  • filter.xml
  • index.jsp
  • web.xml
A filter is configured in the web application's web.xml file.

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.