package br.dsc.upe.poli.mvc;

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

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.dsc.upe.poli.basicas.Professor;
import br.dsc.upe.poli.dao.ProfessorDAO;

/**
 * Servlet implementation class CadastroProfessor
 */
public class CadastroProfessor extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CadastroProfessor() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Professor professor = new Professor();
		String nome = request.getParameter("professorNome");
		String disciplina = request.getParameter("professorDisciplina");
		String identidade = request.getParameter("professorIdentidade");
		String login = request.getParameter("professorLogin");
		String senha = request.getParameter("professorSenha");
		professor.setNome(nome);
		professor.setDisciplina(disciplina);
		professor.setSenha(senha);
		professor.setLogin(login);
		professor.setIdentidade(identidade);
		
		try {
			ProfessorDAO dao = new ProfessorDAO();
			dao.cadastrar(professor);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ServletException(e);
		}
		//RequestDispatcher requestDispatcher = request.getRequestDispatcher("index.jsp");
		response.setStatus(200);
		response.getWriter().flush();  
		//requestDispatcher.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
