What is the role of the Secure flag in a cookie?
- Enables third-party access to the cookie
- Ensures the cookie is encrypted
- Indicates the cookie is safe for cross-site requests
- Restricts the cookie to HTTPS connections
The Secure flag in a cookie indicates that the cookie should only be sent over secure, encrypted connections (HTTPS). This enhances the security of the cookie by preventing it from being transmitted over unsecured HTTP connections.
HTTP persistent connections are managed using the _________ header in servlet responses.
- Connection
- Keep-Alive
- Persistent
- Session
HTTP persistent connections are managed using the Keep-Alive header in servlet responses.
The __________ method is generally used for fetching data where the request does not affect server state.
- DELETE
- GET
- POST
- PUT
The GET method is generally used for fetching data where the request does not affect server state. It is considered idempotent.
To access all initialization parameters, the method ________ can be used, which returns an _________.
- getInitParameterNames(), Enumeration
- getInitParameters(), ArrayList
- getParameters(), Array
- getServletContext(), Enumeration
The correct method is getInitParameterNames(), which returns an Enumeration containing the names of the servlet's initialization parameters.
What is the best approach to maintain user sessions in a distributed web application environment?
- Database Session
- HTTP Session
- Hidden Form Fields
- URL Rewriting
The best approach to maintain user sessions in a distributed web application environment is to use HTTP Session. This allows for centralized session management across multiple servers.
Which method in a filter is responsible for cleaning up resources when the filter is taken out of service?
- destroy()
- doFilter()
- filterInit()
- init()
The destroy() method is responsible for cleaning up resources when the filter is taken out of service.
When designing a servlet that handles sensitive data, which header should be set to secure the response?
- Access-Control-Allow-Origin, setHeader()
- Strict-Transport-Security, setHeader()
- X-Content-Type-Options, setHeader()
- X-Frame-Options, setHeader()
To secure the response when handling sensitive data, the Strict-Transport-Security header should be set using the setHeader() method in the HttpServletResponse.
The scope of ServletContext is:
- Application
- Page
- Request
- Session
The ServletContext has the scope of the entire application (web context). It is used to share information across servlets in the same web application and is often used for initialization and configuration.
How can a filter be configured to process requests for specific servlets or URL patterns?
- By implementing the processOnly method in the filter.
- By setting the filter-url property in the deployment descriptor.
- By specifying servlet names or URL patterns in the filter's configuration.
- By using the @ProcessFor annotation in the filter code.
A filter can be configured to process requests for specific servlets or URL patterns by specifying servlet names or URL patterns in the filter's configuration in the deployment descriptor.
The __________ method is used to initialize the filter with configuration parameters.
- configure(FilterConfig config)
- init(FilterConfig config)
- initialize(FilterConfig config)
- setup(FilterConfig config)
The init(FilterConfig config) method is used to initialize the filter with configuration parameters.