package locadora.servlets;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
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 locadora.modelo.DAO.FilmeDAO;
import locadora.modelo.filmes.Filme;


public class ListaVideos extends HttpServlet {
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
	
		HttpSession session = request.getSession(true);
	//Verifica login
	if(session.getValue("cliente") == null) {
		response.sendRedirect("index.jsp?msg_erro=Acesso Negado");  return;
	} 
	List<Filme> listaFilme = null;  

	
	
	try {
		FilmeDAO lista = new FilmeDAO(); 
		listaFilme = lista.getLista();   
		    
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace(); 
	} 
	session.setAttribute("listaFilmes", listaFilme);  
	  
	 
	String url="/selecao.jsp";    
	ServletContext sc = getServletContext();
	RequestDispatcher rd = sc.getRequestDispatcher(url);
	rd.forward(request, response);  
   }
}

