When a request is processed through multiple filters, how is the order of execution determined in a servlet application?

  • The order is determined alphabetically based on filter names.
  • The order is determined by the order in the web.xml file.
  • The order is determined by the order in which filters are added programmatically in the servlet code.
  • The order is determined randomly at runtime.
The order of execution of filters is determined by the order in which they are declared in the deployment descriptor (web.xml) file. The filters are applied to the request and response objects in the order specified in the deployment descriptor.

Which listener interface in Servlets is used for receiving notification about ServletContext lifecycle changes?

  • HttpSessionListener
  • ServletContextAttributeListener
  • ServletContextListener
  • ServletRequestListener
The ServletContextListener interface is used for receiving notifications about ServletContext lifecycle changes, such as when it is initialized or destroyed.

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.

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.

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.

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.

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.

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.

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.

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.