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.

How do filters interact with different types of servlets and JSP pages?

  • Filters are applied only to static resources
  • Filters can be applied to both servlets and JSP pages
  • Filters can only be applied to servlets
  • Filters cannot be applied to JSP pages
Filters can be applied to both servlets and JSP pages, providing a versatile mechanism for preprocessing and postprocessing of requests and responses in different types of web components.

What is the difference between filter chaining and servlet chaining?

  • Filter chaining is the process of passing a request through multiple filters
  • Filter chaining is the same as servlet chaining
  • Servlet chaining involves calling multiple servlets in a sequence
  • Servlet chaining is the same as filter chaining
Filter chaining involves passing a request through multiple filters in a defined sequence, allowing each filter to process the request. Servlet chaining, on the other hand, involves calling multiple servlets in a sequence.

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.

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.

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.

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.

What is the function of FilterMapping in a web application?

  • Defines the filter's initialization parameters
  • Indicates the filter's scope
  • Maps a filter to a specific servlet or URL pattern
  • Specifies the order of filter execution
FilterMapping in a web application is used to map a filter to a specific servlet or URL pattern. It specifies the conditions under which the filter should be invoked, such as when a particular servlet is accessed or when a specific URL pattern is matched.

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

  • Initialization parameters cannot be accessed by filters
  • Using the FilterConfig object
  • Using the HttpServletRequest object
  • Using the ServletContext object
A filter can access initialization parameters set in the web.xml file through the FilterConfig object, which is passed to the init() method of the filter. The getInitParameter() method of FilterConfig can be used to retrieve the parameter values.

What is a session ID in the context of web applications?

  • A Java programming language keyword
  • A servlet initialization parameter
  • A unique identifier for a user's session
  • An HTML form element
A session ID in the context of web applications is a unique identifier assigned to each user's session, enabling the server to distinguish between different user sessions.

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

  • Using the
  • Using the
  • Using the
  • Using the
URL patterns to which a filter should apply are specified using the element within the element in the web.xml deployment descriptor.

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 in the web application's deployment descriptor is used to declare a filter, specifying its name and class.