Which method is used to send an error status code along with a custom message in the response header?

  • sendError()
  • sendStatusCode()
  • setErrorCode()
  • setErrorMessage()
The sendError() method is used to send an error status code along with a custom message in the response header.

Can a servlet's destroy() method be overridden? If yes, what should be considered?

  • It depends on the servlet container being used.
  • No, the destroy() method cannot be overridden.
  • Yes, but it is not advisable to override it.
  • Yes, it can be overridden, and it is recommended to do so.
Yes, a servlet's destroy() method can be overridden, but it is recommended to do so carefully, ensuring that necessary cleanup operations are performed. Considerations should be given to resource release and proper handling of exceptions in the overridden method.

A web application needs to remember user preferences across sessions. Which approach using cookies is most suitable?

  • HttpOnly Cookies
  • Persistent Cookies
  • Secure Cookies
  • Session Cookies
Persistent Cookies are suitable for remembering user preferences across sessions as they persist even after the user closes the browser.

ServletContext is used for sharing information between:

  • Browser and Server
  • Client and Server
  • JSP and Servlet
  • Web components
ServletContext is used for sharing information between web components within the same web application, like servlets, JSP pages, and other resources.

For optimizing a web application with heavy presentation logic, which technology is more suitable?

  • Both
  • JSP
  • None of the above
  • Servlet
For optimizing a web application with heavy presentation logic, JSP (JavaServer Pages) is more suitable. JSP is specifically designed for creating dynamic web pages with a focus on presentation logic, making it easier to manage and optimize the presentation layer of a web application.

What is the primary purpose of cookies in web applications?

  • To execute server-side code
  • To handle database connections
  • To perform client-side validation
  • To store user preferences
The primary purpose of cookies in web applications is to store user preferences, enabling a personalized and persistent experience for users.

Servlets are often used for processing and sending the ______ to the client.

  • Data
  • HTML
  • Requests
  • XML
Servlets are often used for processing and sending HTML to the client.

What is the difference between context parameters and initialization parameters in servlets?

  • Context parameters are set at the application level, while initialization parameters are specific to a servlet.
  • Context parameters are used for database connectivity, while initialization parameters are used for servlet configuration.
  • Initialization parameters are set at the application level, while context parameters are specific to a servlet.
  • Initialization parameters are used for database connectivity, while context parameters are used for servlet configuration.
Context parameters are set at the application level and are accessible to all servlets, while initialization parameters are specific to each servlet and are defined in the servlet's deployment descriptor (web.xml).

The response header 'Content-Disposition' with value 'attachment; filename="file.txt"' is set using the __________ method.

  • addHeader()
  • sendRedirect()
  • setContentType()
  • setHeader()
The setHeader() method is used to set response headers, including the 'Content-Disposition' for file downloads.

How can you securely send sensitive data from a client to a server in a web application?

  • Encode data in Base64
  • Send data in plain text
  • Use HTTP with custom encryption
  • Use HTTPS (SSL/TLS)
Sensitive data should be sent securely, and using HTTPS (SSL/TLS) ensures encrypted communication between the client and the server, providing a secure way to transmit sensitive information.