Hello. Please help me solve the problem. I need the servlet to forward the user to the specified page. For this I use

req.getRequestDispatcher("/demo/new.jsp").forward(req, resp); 

However, I do not throw on this page. Using

 resp.sendRedirect("/demo/new.jsp"); 
  • everything is working. However, I will need to get some session data. Why does getRequestDispatcher not start?

    1 answer 1

    request.getRequestDispatcher("...").forward(...) performs an internal redirect, i.e. the server internally transfers further request processing to the specified page. At the same time, the client (browser) knows nothing about it.

    response.sendRedirect("...") , on the contrary, performs external (client) redirection, i.e. the server says to the client: “to get the page you requested, go to such an address”, after which the browser changes the address in the address bar and requests the page from the server to this new address.

    • This is a description of the methods, but not the answer to the question. - parkito
    • @parkito Then clarify the question. You asked, "Why is RequestDispatcher not throwing?", I replied that it should not. - Roman