Describe the difference between session cookies and persistent cookies.

  • Persistent cookies are often used for user authentication
  • Persistent cookies are temporary and expire after the browser is closed
  • Session cookies are stored permanently on the client-side
  • Session cookies expire after a specified time
Session cookies are temporary and expire when the browser is closed, while persistent cookies are stored on the client-side for a longer duration, typically with an expiration date set by the server.

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.

Which method of the HttpServlet class is used to handle HTTP GET requests?

  • doGet()
  • doPost()
  • init()
  • service()
The doGet() method of the HttpServlet class is specifically designed to handle HTTP GET requests.

How should a servlet handle session tracking when a user's privacy settings restrict cookie usage?

  • Database Session
  • HTTP Session
  • Hidden Form Fields
  • URL Rewriting
When a user's privacy settings restrict cookie usage, session tracking can be handled using Hidden Form Fields. This involves including session information in HTML forms.

The servlet is removed from service by the servlet container via the __________ method.

  • destroy()
  • doDelete()
  • init()
  • service()
The destroy() method is called when the servlet is being removed from service by the servlet container. It allows the servlet to release resources before it's taken out of operation.

What differentiates ServletContext and ServletConfig in terms of initialization parameters?

  • ServletConfig can be used for application-wide parameters, while ServletContext is specific to a servlet.
  • ServletConfig is used for application-wide parameters.
  • ServletContext can be used for application-wide parameters, while ServletConfig is specific to a servlet.
  • ServletContext is used for servlet-specific parameters.
The ServletContext is intended for parameters that are shared across the entire application, whereas ServletConfig is specific to a particular servlet.