Multiple choice technology web technology

In a Java servlet/JSP, if you attempt to redirect (or forward) after output has already been written and the HTTP response has been committed, what happens?

  1. A java.lang.IllegalStateException is thrown ("response already committed")

  2. An HTTP 402 Payment Required error is returned to the client

  3. An HTTP 404 Not Found error is returned to the client

  4. A java.lang.NullPointerException is thrown

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Once the HTTP response has been committed (headers sent and buffer flushed), the servlet container cannot modify the response to redirect or forward. Attempting to do so triggers an IllegalStateException with the message 'response already committed'. The other options refer to HTTP error codes or different exceptions entirely.

AI explanation

The original statement was false and mis-worded: the 'response already committed' condition in Java servlets is a java.lang.IllegalStateException thrown by HttpServletResponse.sendRedirect()/RequestDispatcher.forward() once the response is committed. It has nothing to do with HTTP 402 (Payment Required). The item was also broken as a True/False question because its options were duplicated (two True, two False). It has been reconstructed into a clean multiple-choice question whose verifiable correct answer is the IllegalStateException, with the four existing options repurposed into distinct choices.