Which method is commonly used for session tracking in servlets?

  • doGet()
  • doPost()
  • getSession()
  • init()
The getSession() method is commonly used for session tracking in servlets. It returns the current session associated with the request or creates a new session if one does not exist.

What is primarily stored in ServletConfig?

  • Context attributes
  • Request parameters
  • Servlet parameters
  • Session data
ServletConfig primarily stores servlet parameters, which are initialization parameters for a servlet.

Which method is used to read form data sent via POST request in a servlet?

  • request.getFormData()
  • request.getParameter()
  • request.readParameter()
  • request.readPostData()
The request.readPostData() method is used to read form data sent via POST request in a servlet.

To redirect the response to another resource, the __________ method is used in servlets.

  • forward()
  • forwardResponse()
  • redirect()
  • sendRedirect()
The sendRedirect() method is used to redirect the response to another resource in servlets.

How can you ensure that a response header is set only once in a servlet?

  • addHeader()
  • sendHeader()
  • setHeader()
  • writeHeader()
The setHeader() method is used to set a response header in a servlet, and it ensures that the specified header is set only once.

What is mainly used for creating the view layer in MVC architecture?

  • CSS
  • HTML
  • JSP
  • Servlets
JavaServer Pages (JSP) are mainly used for creating the view layer in MVC architecture.

For secure data transmission, HTTP servlets utilize the _________ protocol.

  • HTTPS
  • SSL
  • SecureHTTP
  • TLS
For secure data transmission, HTTP servlets utilize the TLS (Transport Layer Security) protocol.

Using sendRedirect, the client makes a new _________, resulting in a separate request to the server.

  • domain
  • request
  • response
  • session
Using sendRedirect, the client makes a new request, resulting in a separate request to the server.

When a form is submitted with the enctype as 'multipart/form-data', how should the form data be handled in a servlet?

  • This is not supported in servlets
  • Use a library like Apache FileUpload
  • Use the getInputStream()
  • Use the getParameter()
When a form is submitted with the enctype as 'multipart/form-data', the form data should be handled using a library like Apache FileUpload for efficient processing of multipart data in servlets.

How does the servlet container pass initialization parameters to the servlet?

  • Through XML configuration
  • Through environment variables
  • Through method parameters
  • Through web.xml
The servlet container passes initialization parameters to the servlet through the web.xml configuration file.