The _________ method of RequestDispatcher is used for including content of another resource in the response.

  • execute()
  • forward()
  • include()
  • sendRedirect()
The include() method of RequestDispatcher is used for including content of another resource in the response.

Servlets can be used to handle ______, while JSP is used for presenting these to the users.

  • HTTP requests
  • business logic
  • database operations
  • presentation
Servlets are commonly used for handling business logic, database operations, etc., while JSP is primarily used for presenting content to users.

A servlet needs to handle a file upload from a web form. Which HTTP method and content type should be used?

  • DELETE with text/plain
  • GET with application/x-www-form-urlencoded
  • POST with multipart/form-data
  • PUT with application/json
For handling file uploads, the appropriate combination is to use the POST method along with the multipart/form-data content type.

ServletContext allows servlets to __________ resources and information.

  • access
  • initialize
  • restrict
  • share
ServletContext allows servlets to share resources and information.

How does the servlet container handle thread safety in the case of servlets?

  • By creating a new thread for each request.
  • By making the service() method synchronized.
  • By using a single thread for all requests.
  • Thread safety is the responsibility of the developer.
The servlet container handles thread safety by making the service() method synchronized to ensure that only one thread executes it at a time, preventing race conditions in shared resources.

Which HTTP method is idempotent: GET or POST?

  • DELETE
  • GET
  • POST
  • PUT
The GET method is idempotent, meaning multiple identical requests have the same effect as a single request. This is because GET requests do not change the state on the server.

A cookie's security can be enhanced by setting the _________ flag, which prevents its access via JavaScript.

  • HttpOnly
  • Max-Age
  • Path
  • Secure
The HttpOnly flag enhances a cookie's security by preventing its access via JavaScript.

How can servlet initialization parameters be used effectively for database connectivity?

  • By embedding database connection details directly in the servlet code.
  • By relying on default database configurations provided by the servlet container.
  • By storing database connection details as initialization parameters and retrieving them in the servlet's init() method.
  • By using context parameters instead of initialization parameters for database connectivity.
Servlet initialization parameters can be used effectively for database connectivity by storing database connection details in the web.xml file and retrieving them in the servlet's init() method for establishing connections.

The scope of ServletContext is:

  • Application
  • Page
  • Request
  • Session
The ServletContext has the scope of the entire application (web context). It is used to share information across servlets in the same web application and is often used for initialization and configuration.

What is the difference in the URL seen by the client when using forward() vs sendRedirect() in servlets?

  • The client sees the new URL in both cases
  • The client sees the new URL with forward() and the original URL with sendRedirect()
  • The client sees the original URL in both cases
  • The client sees the original URL with forward() and the new URL with sendRedirect()
The difference lies in what the client sees: with forward(), the client sees the original URL, while with sendRedirect(), the client sees the new URL.