package com.roshka.bootcamp; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; @WebServlet("/login") public class RequestDispatcherServlet extends HttpServlet { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String username = request.getParameter("username"); String password = request.getParameter("password"); if (username.equals("bootcamp") && password.equals("bootcamp")) { // forward RequestDispatcher dispatcher = request.getRequestDispatcher("/success"); dispatcher.forward(request, response); } else { RequestDispatcher rd = request.getRequestDispatcher("login-try.html"); rd.forward(request, response); } } @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher rd = request.getRequestDispatcher("/login.html"); rd.forward(request, response); } }