/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package PackServlet;
import PackDAO.DisciplinaDAO;
import PackDisciplina.Disciplina;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Vinnicyus
*/
public class ValidarDisciplina extends HttpServlet{
public void doGet(HttpServletRequest p_request, HttpServletResponse p_response) throws IOException, ServletException {
DisciplinaDAO Ddao = new DisciplinaDAO();
String disciplina = p_request.getParameter("nome");
int id = -1;
try {
id = Ddao.buscaDisciplinaPorNome(disciplina);
Disciplina di = new Disciplina(disciplina);
if(id==-1) {
try {
Ddao.cadDisciplina(di);
p_request.setAttribute("Mensagem", "Cadastrado com Sucesso!!!");
p_request.getRequestDispatcher("/interface/disciplina/cad_disciplinas.jsp").forward(p_request, p_response);
} catch (SQLException ex) {
Logger.getLogger(ValidarDisciplina.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ValidarDisciplina.class.getName()).log(Level.SEVERE, null, ex);
}
}
else {
p_request.setAttribute("Mensagem", "Disciplina já existe.");
p_request.getRequestDispatcher("/interface/disciplina/cad_disciplinas.jsp").forward(p_request, p_response);
}
} catch (SQLException ex) {
Logger.getLogger(ValidarDisciplina.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(ValidarDisciplina.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void doPost(HttpServletRequest p_request, HttpServletResponse p_response) throws IOException, ServletException {
doGet(p_request, p_response);
}
}