How does the load-on-startup element in web.xml affect a servlet's lifecycle?

  • It controls the number of instances created for a servlet when handling client requests.
  • It decides whether a servlet should be loaded automatically or on demand.
  • It determines the order in which servlets are initialized when the application starts.
  • It specifies the maximum number of times a servlet can be loaded during the application's lifecycle.
The load-on-startup element in the web.xml file specifies the order in which servlets should be initialized when the application starts. Servlets with lower values are initialized first.

Describe how you would configure a filter to initialize with predefined parameters.

  • Implement the init() method in the filter
  • Set parameters in the doFilter() method
  • Use a configuration file
  • Use the in the deployment descriptor
To configure a filter with predefined parameters, use the element in the deployment descriptor (web.xml) to specify initialization parameters. These parameters can be accessed in the filter using the getInitParameter() method.

What is the correct order of method invocation in a filter's lifecycle?

  • destroy(), init(), doFilter()
  • doFilter(), init(), destroy()
  • init(), destroy(), doFilter()
  • init(), doFilter(), destroy()
The correct order of method invocation in a filter's lifecycle is init(), doFilter(), and destroy().

The __________ method of the FilterChain interface is used to invoke the next filter in the chain.

  • doFilter()
  • invokeNext()
  • nextFilter()
  • proceed()
The doFilter() method of the FilterChain interface is used to invoke the next filter in the chain.

The filter's __________ method is invoked for every request/response pair processed by the filter.

  • doFilter()
  • doProcessing()
  • execute()
  • process()
The filter's doFilter() method is invoked for every request/response pair processed by the filter.

The method __________ is used to handle request and response objects in a filter.

  • doFilter()
  • filterRequest()
  • initFilter()
  • processFilter()
The method doFilter() is used to handle request and response objects in a filter.

Filters are configured in the __________ file of a web application.

  • filter-config.xml
  • filter.xml
  • web-config.xml
  • web.xml
Filters are configured in the web.xml file of a web application.

When implementing a filter, it's critical to maintain the correct order of processing by calling __________ in the doFilter method.

  • doProcessing.filter()
  • filterChain.doFilter()
  • filterOrder.doFilter()
  • servletRequest.process()
In the doFilter method of a filter, it's important to call filterChain.doFilter() to ensure the correct order of processing continues.

What is the primary purpose of a filter chain in a servlet environment?

  • To establish a secure connection
  • To execute servlets sequentially
  • To handle exceptions in a servlet
  • To perform multiple filters on a request and response
The primary purpose of a filter chain is to allow multiple filters to be applied to a request and response in a sequential order, enabling the execution of various processing tasks.

How does a filter pass the request and response to the next entity in the filter chain?

  • Automatically passed by the servlet container
  • By directly calling the next filter
  • By setting a flag in the request
  • Using the chain.doFilter() method
A filter passes the request and response to the next entity in the filter chain using the chain.doFilter() method, which allows the request and response to move to the next filter or servlet in the chain.