Consider a scenario where a request needs to be authenticated and then logged. How should the filters be arranged in the filter chain?

  • Authenticate, Log, Other Filters, Process Request
  • Authenticate, Other Filters, Log, Process Request
  • Log, Authenticate, Other Filters, Process Request
  • Other Filters, Authenticate, Log, Process Request
In this scenario, it is ideal to perform authentication before logging. Therefore, the correct order is to place the authentication filter before the logging filter in the filter chain. This ensures that the request is authenticated first, and then the logging is done.

To apply multiple filters to a single resource, the web.xml file must define a __________ for each filter.

  • filter-chain
  • filter-group
  • filter-list
  • filter-mapping
In the web.xml file, a filter-mapping element must be defined for each filter to apply multiple filters to a single resource.

Filters can be used to manipulate the __________ and __________ before they reach a servlet or JSP.

  • context, attributes
  • headers, body
  • request, response
  • session, cookie
Filters can manipulate the request and response objects before they reach a servlet or JSP, allowing for various pre-processing tasks.

The __________ object provides the filter with information about its initialization parameters.

  • FilterConfig
  • FilterContext
  • InitParams
  • ServletContext
The FilterConfig object provides the filter with information about its initialization parameters, allowing the filter to retrieve its configuration.

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

  • destroy()
  • dispose()
  • remove()
  • unregister()
The destroy() method is called by the web container to indicate that a filter is being taken out of service.

What is the primary use of the ServletContextAttributeListener in a web application?

  • To handle changes in session attributes.
  • To listen for changes in the servlet context.
  • To monitor changes in attributes at the application scope.
  • To track the addition or removal of servlets in the application.
The primary use of ServletContextAttributeListener is to monitor changes in attributes at the application scope, such as when attributes are added, removed, or replaced in the ServletContext.

The __________ element in web.xml is used to define a logical name for a servlet.

  • logical-name
  • name
  • servlet-logical
  • servlet-name
The element in web.xml is used to define a logical name for a servlet.

For monitoring changes to the session's attribute list, which listener interface is suitable?

  • HttpSessionAttributeListener
  • HttpSessionBindingListener
  • ServletContextListener
  • ServletRequestListener
The HttpSessionAttributeListener interface is suitable for monitoring changes to the session's attribute list.

Which listener is used to track changes to the attributes of the ServletRequest?

  • HttpSessionListener
  • ServletContextListener
  • ServletRequestAttributeListener
  • ServletRequestListener
The ServletRequestAttributeListener interface is used to track changes to the attributes of the ServletRequest, such as when an attribute is added, removed, or replaced.

If you want to perform some task when a session is created or destroyed, which listener should you implement?

  • HttpSessionAttributeListener
  • HttpSessionListener
  • ServletContextListener
  • ServletRequestListener
The HttpSessionListener interface is used to perform tasks when a session is created or destroyed.

When a session is passivated or activated, the __________ interface provides the necessary notifications.

  • ActivationEventListener
  • HttpSessionActivationEvent
  • SessionActivationListener
  • SessionPassivationEvent
The HttpSessionActivationEvent interface provides the necessary notifications when a session is passivated or activated.

To track the creation and destruction of HttpSession objects, the _________ interface is implemented.

  • HttpSessionEvent
  • HttpSessionListener
  • HttpSessionTracker
  • SessionLifecycleListener
The HttpSessionListener interface is implemented to track the creation and destruction of HttpSession objects.