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.

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 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 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.

Can a filter modify the request and response objects?

  • Depends on servlet version
  • No
  • Sometimes
  • Yes
Yes, a filter can modify the request and response objects before they reach the servlet or after they leave the servlet, providing a mechanism to pre-process or post-process the request and response.

What is the difference between filter chaining and servlet chaining?

  • Filter chaining is sequential execution of multiple filters before the servlet is invoked.
  • Filter chaining is used only for static resources.
  • Servlet chaining is sequential execution of multiple servlets before the response is sent to the client.
  • There is no difference.
Filter chaining involves the sequential execution of multiple filters before the servlet is invoked, allowing each filter to process the request or response. Servlet chaining involves the sequential execution of multiple servlets before the response is sent to the client.

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

  • Filters can interact with both servlets and JSP pages in the same way.
  • Filters can only interact with JSP pages, not servlets.
  • Filters can only interact with servlets, not JSP pages.
  • It depends on the filter configuration.
Filters can interact with both servlets and JSP pages in the same way, providing a unified mechanism for processing requests and responses in web applications.

The __________ object provides the filter with its configuration information.

  • FilterChain
  • FilterConfig
  • HttpServletRequest
  • ServletContext
The FilterConfig object provides the filter with its configuration information.

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

  • filter-mapping
  • filter-name
  • servlet-mapping
  • url-pattern
In the deployment descriptor, the url-pattern tag is used to specify which requests are passed through a particular filter.

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

  • continueChain()
  • doFilter()
  • doNext()
  • passOn()
To pass the request and response to the next entity in the chain, the filter uses the doFilter() method.