In a web application, you need to audit changes to session attributes. Which listener would you implement?

  • HttpSessionAttributeListener
  • HttpSessionBindingListener
  • HttpSessionEvent
  • HttpSessionListener
The HttpSessionAttributeListener interface is used to audit changes to session attributes. This allows you to perform actions when attributes are added, removed, or replaced in a session.

What is the purpose of the FilterConfig object in Servlet filters?

  • To define filter order.
  • To hold configuration parameters for a filter.
  • To process HTTP requests.
  • To store filter mappings.
The FilterConfig object is used to hold configuration parameters for a filter, allowing the filter to be customized without modifying the filter code itself.

How do you specify the URL patterns to which a filter should apply?

  • By modifying the servlet code.
  • In the filter's constructor.
  • In the web server settings.
  • Using the
URL patterns to which a filter should apply are specified using the element inside the element in the web.xml file. This defines the URLs that the filter will intercept.

How can a filter access initialization parameters set in the web.xml file?

  • By using the FilterConfig object
  • By using the HttpResponse object
  • By using the HttpServletRequest object
  • By using the ServletContext object
A filter can access initialization parameters set in the web.xml file by using the FilterConfig object. This object provides methods to retrieve initialization parameters.

The __________ object provides the filter with its configuration information.

  • FilterConfig
  • FilterContext
  • ResponseConfig
  • ServletRequest
The FilterConfig object provides the filter with its configuration information. It is passed to the init() method of the filter during initialization.

In the deployment descriptor, the __________ tag is used to specify which requests are passed through a particular filter.

In the deployment descriptor, the tag is used to specify which requests are passed through a particular filter by associating it with a filter name and a URL pattern.

To pass the request and response to the next entity in the chain, the filter uses the __________ method.

  • chain.continue()
  • chain.doFilter()
  • chain.doNext()
  • chain.forward()
To pass the request and response to the next entity in the chain, the filter uses the chain.doFilter() method. This method is invoked to invoke the next filter or the servlet in the chain.

The sequence of filters applied to a request is determined by the order of _______ in the web.xml file.

  • filter
  • filter-mapping
  • filter-order
  • web-filter
The sequence of filters applied to a request is determined by the order of filter-mapping elements in the web.xml file.

A filter can alter the header information of a request or response by modifying the _______.

  • HttpServletRequest
  • HttpServletResponse
  • RequestHeader
  • ServletResponse
A filter can alter the header information of a request or response by modifying the ServletResponse.

Which XML element is used to declare a filter in a web application's deployment descriptor?

  • filter
  • filter-mapping
  • servlet-filter
  • web-filter
The element is used to declare a filter in a web application's deployment descriptor (web.xml). This element contains the filter name and the fully qualified class name of the filter.