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.

The _________ listener is invoked when an attribute is added, removed, or replaced in a session.

  • HttpSessionAttribute
  • HttpSessionBinding
  • HttpSessionEvent
  • SessionAttributeListener
The HttpSessionBinding listener is invoked when an attribute is added, removed, or replaced in a session.

To respond to events like the initialization or destruction of the ServletContext, use the _________ listener.

  • ContextInitializationListener
  • ServletConfigListener
  • ServletContextEvent
  • ServletContextListener
Use the ServletContextListener to respond to events like the initialization or destruction of the ServletContext.

The __________ listener is useful for monitoring changes in request attributes during the lifespan of a request.

  • RequestAttribute
  • RequestAttributeChange
  • ServletRequestAttribute
  • ServletRequestAttributeListener
The ServletRequestAttributeListener is useful for monitoring changes in request attributes during the lifespan of a request.

In a web application tracking user login and logout, which listeners would be most effective?

  • HttpSessionAttributeListener
  • HttpSessionListener
  • ServletContextListener
  • ServletRequestListener
The HttpSessionListener is most effective for tracking user login and logout in a web application as it provides notifications about session creation and destruction.

If an application needs to clean up resources when the application is shut down, which listener should be used?

  • HttpSessionListener
  • ServletContextAttributeListener
  • ServletContextListener
  • ServletRequestListener
The ServletContextListener is used to perform actions during the initialization and destruction of the web application, making it suitable for cleaning up resources on application shutdown.

For an e-commerce application that needs to track user session activity and attribute changes, what combination of listeners would be ideal?

  • HttpSessionAttributeListener
  • HttpSessionListener
  • ServletContextListener
  • ServletRequestListener
The ideal combination for tracking user session activity and attribute changes in an e-commerce application is to use HttpSessionListener and HttpSessionAttributeListener together.

What is the primary purpose of using filters in web applications?

  • To handle HTTP requests and responses
  • To manage session information
  • To perform tasks before or after the request is handled by a servlet
  • To store data in the client's browser
The primary purpose of using filters in web applications is to perform tasks before or after the request is handled by a servlet, allowing for common processing tasks to be centralized.

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.

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.