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