Commit 808c1385 by OscarGonzalez97

correcciones en ejemplos de RequestDispatcher

parent d4b588da
......@@ -23,14 +23,18 @@ public class RequestDispatcherServlet extends HttpServlet {
if (username.equals("bootcamp") && password.equals("bootcamp")) {
// forward
RequestDispatcher dispatcher = request.getRequestDispatcher("RequestDispatcherServletSuccess");
RequestDispatcher dispatcher = request.getRequestDispatcher("/success");
dispatcher.forward(request, response);
} else {
//include
out.print("Usuario invalido!");
RequestDispatcher rd = request.getRequestDispatcher("/login.html");
rd.include(request, response);
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);
}
}
......@@ -9,7 +9,7 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/dispatcher")
@WebServlet("/success")
public class RequestDispatcherServletSuccess extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="estilos/login.css"></link>
</head>
<body>
<form method="post" action="login">
<h2 style="color:red;">username o password invalido</h2>
<label>username: </label>
<input type="text" name="username"><br/>
<label>password: </label>
<input type="password" name="password"><br/>
<input type="submit">
</form>
</body>
</html>
\ No newline at end of file
......@@ -9,6 +9,7 @@
<form method="post" action="login">
<label>username: </label>
<input type="text" name="username"><br/>
<label>password: </label>
<input type="password" name="password"><br/>
<input type="submit">
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment