Update ResourcesControllerIndex.java

This commit is contained in:
aqpcalel 2018-06-16 00:42:55 -05:00 committed by GitHub
parent 44b926e57d
commit f022c7de4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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("<html><head><script>window.location.replace(\"../\")</script></head><body></body></html>");
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {