🎴 Flashcard Mode

Java Programming and OOP Concepts

Card1 / 11
Mastered0
Review0
QuestionClick to flip

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); }

AnswerClick to flip back
A
NullPointerException.
💡 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.

Change Mode