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.
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.
Filters can be used to implement ________, which is a common requirement in web applications.
- authentication
- authorization
- caching
- logging
Filters can be used to implement authorization, which is a common requirement in web applications.
If a filter needs to perform different actions based on the type of HTTP request, which method or object should it use to determine this?
- doFilter()
- getContentType()
- getRequestDispatcher()
- getRequestType()
The doFilter() method in a filter is responsible for performing different actions based on the type of HTTP request. This method is invoked by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.
In a scenario where a filter needs to restrict access based on user roles, which object or method is essential for implementing this?
- checkUserRole()
- getRoleNames()
- getUserPrincipal()
- getUserRoles()
The getUserPrincipal() method is essential for implementing access restrictions based on user roles in a filter. It returns a java.security.Principal object representing the user making the request. The filter can then extract information from this object, such as the user's roles, to make decisions about whether to allow or deny access.
How would a filter log request information without altering the request itself?
- filterConfig.log(request)
- getServletContext().log(request)
- logger.log(request)
- request.log()
To log request information without altering the request itself, the filter should use the getServletContext().log(request) method. This allows the filter to log information through the servlet context, providing a way to record information without modifying the request or response objects.