JSP is a technology on the server side to make ______ easier.

  • Client-side scripting
  • Java programming
  • Server-side scripting
  • Web development
JSP (JavaServer Pages) is a technology on the server side to make server-side scripting easier. It allows the embedding of Java code in HTML pages for dynamic content generation.

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.

Can a servlet access the ServletConfig of another servlet?

  • It depends on the web container being used.
  • No
  • Only if both servlets belong to the same package.
  • Yes
No, a servlet cannot directly access the ServletConfig of another servlet. Each servlet has its own ServletConfig associated with it.

If an HTTP servlet receives a request with an invalid session token, what should it do next?

  • Generate a new session token and proceed
  • Ignore the request
  • Redirect to the login page
  • Send an HTTP 401 Unauthorized response
In the case of an invalid session token, it's a security best practice to send an HTTP 401 Unauthorized response to prompt reauthentication.

Which method of the RequestDispatcher interface is used to forward a request from a servlet to another resource?

  • dispatch()
  • forward()
  • forwardRequest()
  • redirect()
The forward() method of the RequestDispatcher interface is used to forward a request from a servlet to another resource within the same server.

In what scenario is it more appropriate to use RequestDispatcher over HttpServletResponse's sendRedirect?

  • When maintaining the original URL is crucial
  • When preserving client-side state is necessary
  • When the resource is on a different server
  • When the resource is on the same server
RequestDispatcher is more appropriate when you need to forward a request internally within the server, maintaining the original URL. This is especially important when you want to keep the original URL in the browser's address bar.

How does the servlet container handle HTTP headers when using RequestDispatcher's forward method?

  • HTTP headers are discarded
  • HTTP headers are duplicated
  • HTTP headers are modified
  • HTTP headers are preserved
When using RequestDispatcher's forward method, the servlet container discards the original response headers, allowing the forwarded resource to generate a new set of headers. This is important to avoid conflicts and ensure that the forwarded resource has control over the headers.