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.

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.

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

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

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

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.

How does session tracking differ between stateless and stateful protocols?

  • Stateful: Lightweight
  • Stateful: Stores client state
  • Stateless: No memory of previous requests
  • Stateless: Uses cookies
Stateless protocols, like HTTP, have no memory of previous requests, while stateful protocols, like HTTPS, store client state, allowing continuity across multiple requests.

To prevent character encoding issues when reading form data, the method __________ should be called before any getParameter methods.

  • encodeCharacters
  • handleEncoding
  • resolveCharacterIssues
  • setCharacterEncoding
To prevent character encoding issues when reading form data, the setCharacterEncoding method should be called before any getParameter methods. This ensures correct interpretation of characters in the form data.

The method __________ of the HttpServletRequest is used to read binary data from a form input.

  • getBinaryData()
  • getInputStream()
  • readBinaryData()
  • readFormData()
The getInputStream() method of the HttpServletRequest is used to read binary data from a form input.