diff --git a/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java b/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java index 028df26..5e8d5a0 100644 --- a/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java +++ b/src/main/java/com/roshka/proyectofinal/login/LoginServlet.java @@ -71,25 +71,22 @@ public class LoginServlet extends HttpServlet { String target = (String) session.getAttribute("login.target"); //response.sendRedirect("loginSuccess.jsp"); //out.println(" \n Destino: " + target); - if (target != null) - response.sendRedirect(target); - //return; + if (target != null){ + response.sendRedirect(target);} + else{ + // Si no es posible redireccionar a la pagina solicitada, llevar a la main page + response.sendRedirect("menu.jsp"); + } } catch (Exception ignored) { } - // Si no es posible redireccionar a la pagina solicitada, llevar a la main page - RequestDispatcher rd = request.getRequestDispatcher("menu.jsp"); - rd.include(request,response); - } else { //si no es un user valido - mandar error y redireccionar al inicio de sesion - RequestDispatcher rd = request.getRequestDispatcher("/login.jsp"); - //out.print("
"); - rd.include(request,response); - } + response.sendRedirect(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() +"/login.jsp"); + } } diff --git a/src/main/java/com/roshka/proyectofinal/login/ProtectedResource.java b/src/main/java/com/roshka/proyectofinal/login/ProtectedResource.java index 980e356..fd48b02 100644 --- a/src/main/java/com/roshka/proyectofinal/login/ProtectedResource.java +++ b/src/main/java/com/roshka/proyectofinal/login/ProtectedResource.java @@ -31,9 +31,5 @@ public class ProtectedResource extends HttpServlet { // El usuario se loggeo y puede ver el recurso out.println("PUEDES ACCEDER AL RECURSO - ESTAS LOGGEADO"); - - - - } } \ No newline at end of file diff --git a/src/main/webapp/formulario_bootcamp.jsp b/src/main/webapp/formulario_bootcamp.jsp index 4021585..cc4cccb 100644 --- a/src/main/webapp/formulario_bootcamp.jsp +++ b/src/main/webapp/formulario_bootcamp.jsp @@ -1,6 +1,16 @@ -<%@ page import="com.roshka.proyectofinal.entity.Lenguaje, com.roshka.proyectofinal.entity.Bootcamp, com.roshka.proyectofinal.lenguaje.LenguajeDao, com.roshka.proyectofinal.bootcamp.BootcampDao, com.roshka.proyectofinal.entity.Profesor, com.roshka.proyectofinal.profesor.ProfesorDao, java.util.List,java.util.Iterator, java.util.ArrayList" %> +<%@ page import="com.roshka.proyectofinal.entity.Lenguaje, com.roshka.proyectofinal.entity.Bootcamp, com.roshka.proyectofinal.lenguaje.LenguajeDao, com.roshka.proyectofinal.bootcamp.BootcampDao, com.roshka.proyectofinal.entity.Profesor, com.roshka.proyectofinal.profesor.ProfesorDao, java.util.List,java.util.Iterator, java.util.ArrayList, jakarta.servlet.http.* , java.lang.Object" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + <%HttpSession session1 = request.getSession(true); + Object done = session1.getAttribute("logon.isDone"); + if (done == null) { + session1.setAttribute("login.target", HttpUtils.getRequestURL(request).toString()); + response.sendRedirect(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() +"/login.jsp"); + return; + + }%> + diff --git a/src/main/webapp/formulario_lenguaje.jsp b/src/main/webapp/formulario_lenguaje.jsp index 20f90b5..e3ea9fd 100644 --- a/src/main/webapp/formulario_lenguaje.jsp +++ b/src/main/webapp/formulario_lenguaje.jsp @@ -1,3 +1,17 @@ + <%@ page import= "jakarta.servlet.http.* , java.lang.Object" %> + <%HttpSession session1 = request.getSession(true); + Object done = session1.getAttribute("logon.isDone"); + if (done == null) { + session1.setAttribute("login.target", HttpUtils.getRequestURL(request).toString()); + response.sendRedirect(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() +"/login.jsp"); + return; + + }%> + + + + + <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> diff --git a/src/main/webapp/formulario_profesor.jsp b/src/main/webapp/formulario_profesor.jsp index 6848d26..4be69b3 100644 --- a/src/main/webapp/formulario_profesor.jsp +++ b/src/main/webapp/formulario_profesor.jsp @@ -1,3 +1,17 @@ + <%@ page import= "jakarta.servlet.http.* , java.lang.Object" %> + <%HttpSession session1 = request.getSession(true); + Object done = session1.getAttribute("logon.isDone"); + if (done == null) { + session1.setAttribute("login.target", HttpUtils.getRequestURL(request).toString()); + response.sendRedirect(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() +"/login.jsp"); + return; + + }%> + + + + + <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> diff --git a/src/main/webapp/menu.jsp b/src/main/webapp/menu.jsp index 381460b..e8bc257 100644 --- a/src/main/webapp/menu.jsp +++ b/src/main/webapp/menu.jsp @@ -1,3 +1,17 @@ + <%@ page import= "jakarta.servlet.http.* , java.lang.Object" %> + <%HttpSession session1 = request.getSession(true); + Object done = session1.getAttribute("logon.isDone"); + if (done == null) { + session1.setAttribute("login.target", HttpUtils.getRequestURL(request).toString()); + response.sendRedirect(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() +"/login.jsp"); + return; + + }%> + + + + +