Multiple choice technology programming languages

From the available options, what is the likely outcome from running the code below? (Choose one.) protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = getServletContext().getNamedDispatcher("/ServletB"); dispatcher.forward(request, response); }

  1. DispatcherNotFoundException.

  2. Runtime error because of incorrectly formed parameter to getNamedDispatcher() method.

  3. NullPointerException.

  4. ServletB can obtain request attribute javax.servlet.forward.request_uri.

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

The getNamedDispatcher method expects a servlet name, not a path starting with a slash. Passing a path like /ServletB will fail to find the servlet and return null, causing a NullPointerException when dispatcher.forward is called on the resulting null reference.