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.

How does the servlet container use the order of filter mappings in web.xml?

  • Filters are executed based on the order of their registration in the servlet container
  • Filters are executed based on the order specified in web.xml
  • Filters are executed in alphabetical order
  • Filters are executed in random order
The servlet container uses the order of filter mappings in web.xml to determine the sequence in which filters are executed. Filters are executed based on the order specified in web.xml.

Can a filter modify the request and response objects?

  • No
  • Yes, both request and response objects
  • Yes, only request object
  • Yes, only response object
Filters have the ability to modify both the request and response objects, allowing them to manipulate data during the processing of a request.

The method __________ is used to set the length of the content body in the response.

  • setBodyLength()
  • setContentLength()
  • setContentSize()
  • setResponseLength()
The setContentLength() method is used to set the length of the content body in the response.