Commit 808c1385 by OscarGonzalez97

correcciones en ejemplos de RequestDispatcher

parent d4b588da
...@@ -23,14 +23,18 @@ public class RequestDispatcherServlet extends HttpServlet { ...@@ -23,14 +23,18 @@ public class RequestDispatcherServlet extends HttpServlet {
if (username.equals("bootcamp") && password.equals("bootcamp")) { if (username.equals("bootcamp") && password.equals("bootcamp")) {
// forward // forward
RequestDispatcher dispatcher = request.getRequestDispatcher("RequestDispatcherServletSuccess"); RequestDispatcher dispatcher = request.getRequestDispatcher("/success");
dispatcher.forward(request, response); dispatcher.forward(request, response);
} else { } else {
//include RequestDispatcher rd = request.getRequestDispatcher("login-try.html");
out.print("Usuario invalido!"); rd.forward(request, response);
RequestDispatcher rd = request.getRequestDispatcher("/login.html"); }
rd.include(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; ...@@ -9,7 +9,7 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@WebServlet("/dispatcher") @WebServlet("/success")
public class RequestDispatcherServletSuccess extends HttpServlet { public class RequestDispatcherServletSuccess extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 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 @@ ...@@ -9,6 +9,7 @@
<form method="post" action="login"> <form method="post" action="login">
<label>username: </label> <label>username: </label>
<input type="text" name="username"><br/> <input type="text" name="username"><br/>
<label>password: </label>
<input type="password" name="password"><br/> <input type="password" name="password"><br/>
<input type="submit"> <input type="submit">
</form> </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