diff --git a/src/controller/resources/ResourcesControllerIndex.java b/src/controller/resources/ResourcesControllerIndex.java index 29e617b..b0b1836 100644 --- a/src/controller/resources/ResourcesControllerIndex.java +++ b/src/controller/resources/ResourcesControllerIndex.java @@ -1,15 +1,41 @@ package controller.resources; +import controller.users.UsersControllerView; +import model.User; + +import javax.jdo.PersistenceManager; +import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import java.io.IOException; @SuppressWarnings("serial") public class ResourcesControllerIndex extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + //Se usa para revisar si hay una sesion activa + HttpSession sesion= request.getSession(); + //Intenta hallar una sesion activa + try{ + User user = UsersControllerView.getUser(sesion.getAttribute("userID").toString()); + if (user == null) throw new NullPointerException("UsersControllerIndex: El usuario recibido es nulo."); + + request.setAttribute("User",user); + request.setAttribute("ResourceList",RolesControllerView.getAllRoles()); + RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/View/Resource/index.jsp"); + dispatcher.forward(request,response); + + } + //Si no la encuentra, redirige a la pagina inicial. + catch (Exception e){ + e.printStackTrace(); + response.getWriter().println("
"); + } + } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {