To delete a cookie, the servlet should set its _________ to a past date.

  • creation time
  • domain
  • expiration date
  • path
To delete a cookie, the servlet should set its expiration date to a past date, making it immediately invalid.

ServletConfig's getServletName() method returns the __________ of the servlet.

  • ID
  • alias
  • handle
  • name
ServletConfig's getServletName() method returns the name of the servlet.

The __________ method of HttpServletResponse causes the browser to request a new URL.

  • forward()
  • include()
  • refresh()
  • sendRedirect()
The sendRedirect() method of HttpServletResponse causes the browser to request a new URL.

To set the character encoding for the response body, use the __________ method of HttpServletResponse.

  • setCharacterEncoding()
  • setContentType()
  • setEncoding()
  • setResponseEncoding()
The setCharacterEncoding() method of HttpServletResponse is used to set the character encoding for the response body.

The method ___________ is used to read a single initialization parameter in the servlet.

  • fetchParameter()
  • getInitParam()
  • getInitParameter()
  • readInitParameter()
The method getInitParameter() is used to read a single initialization parameter in the servlet.

To handle JSON data in a POST request, a servlet may need to parse the request body using a _________.

  • HttpServletRequest
  • HttpServletResponse
  • JsonObject
  • JsonReader
In a POST request, to handle JSON data, a servlet may need to parse the request body using a JsonObject.

In servlets, thread-safety issues are often handled in the __________ method.

  • destroy()
  • doPost()
  • init()
  • service()
In servlets, thread-safety issues are often handled in the init() method.

A servlet's URL pattern is specified in the __________ element in the web application's deployment descriptor.

  • servlet-mapping
  • servlet-url
  • url-mapping
  • url-pattern
The url-pattern element in the web application's deployment descriptor is used to specify a servlet's URL pattern, mapping it to a particular servlet.

The __________ method invalidates the current session and removes its binding from the context.

  • destroySession()
  • endSession()
  • invalidate()
  • removeSession()
The invalidate() method invalidates the current session and removes its binding from the context.

What changes are required in a servlet to handle multipart/form-data requests?

  • Implement a custom parsing algorithm
  • Implement doPost method
  • No changes needed
  • Set content type to multipart/form-data
To handle multipart/form-data requests, set the content type to multipart/form-data in the servlet. This allows the servlet to recognize and process multipart requests correctly, especially when dealing with file uploads or other complex data structures.

Cookies used for tracking user sessions are typically called _________ cookies.

  • Persistent
  • Secure
  • Session
  • Tracking
Cookies used for tracking user sessions are typically called Session cookies.

In a web application with multiple servlets needing a shared resource, where should this resource be initialized?

  • In a Servlet class constructor
  • In the contextInitialized() method of ServletContextListener
  • In the doGet() method of each servlet
  • In the init() method of each servlet
For a shared resource across multiple servlets, it's best to initialize it in the contextInitialized() method of a ServletContextListener, ensuring it's available when the application starts.