package com.hospital.fase.prog3.Action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.fase.prog3.Dao.ConnectionFactory;
import com.hospital.fase.prog3.Dao.JDBCPacienteDAO;
import com.hospital.fase.prog3.Model.Paciente;

/**
 * Servlet implementation class upDatePacienteServlet
 */
@WebServlet("/upDatePacienteServlet")
public class upDatePacienteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public upDatePacienteServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
		
		PrintWriter out = response.getWriter();
		ConnectionFactory cf = new ConnectionFactory();
		Connection conn = cf.getConnection();
		JDBCPacienteDAO dao =new JDBCPacienteDAO(conn); 
		Paciente paciente = new Paciente ();
		
		paciente.setNomePaciente(request.getParameter("nome"));
		paciente = dao.buscar(paciente);
		request.setAttribute("paciente", paciente);
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("Pesquisa_Paciente.jsp");
		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
		request.setAttribute("paciente", ""); //
		String nomeBotaoChamado = request.getParameter("botao");
		if (nomeBotaoChamado.equals("Buscar")) {
			buscar(request, response);
		} else {
			alterar(request, response);
		}

	}

	private void alterar(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	private void buscar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		ConnectionFactory cf = new ConnectionFactory();
		Connection conn = cf.getConnection();
		JDBCPacienteDAO dao =new JDBCPacienteDAO(conn); 
		Paciente paciente = new Paciente ();
		int pront = Integer.parseInt(request.getParameter("pront"));

		paciente.setProntuario(pront);
		paciente = dao.buscar(paciente);
		request.setAttribute("paciente", paciente);
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("Pesquisa_Paciente.jsp");
		requestDispatcher.forward(request, response);

	}

}

@@ -2386,16 +2386,1193 @@
 d stub%0D%0A
+%09%09System.out.println(%22alterando%22);%0D%0A%09%09ConnectionFactory cf = new ConnectionFactory();%0D%0A%09%09Connection conn = cf.getConnection();%0D%0A%09%09JDBCPacienteDAO dao =new JDBCPacienteDAO(conn); %0D%0A%09%09Paciente paciente = new Paciente ();%0D%0A%09%09int pront = Integer.parseInt(request.getParameter(%22pront%22));%0D%0A%0D%0A%09%09paciente.setProntuario(pront);%0D%0A%09%09paciente.setNomePaciente(request.getParameter(%22nome%22));%0D%0A%09%09paciente.setNomePai(request.getParameter(%22pai%22));%0D%0A%09%09paciente.setNomeMae(request.getParameter(%22mae%22));%0D%0A%09%09paciente.setDtNascimento(request.getParameter(%22data%22));%0D%0A%09%09paciente.setRg(request.getParameter(%22rge%22));%0D%0A%09%09paciente.setCpf(request.getParameter(%22cpf%22));%0D%0A%09%09paciente.setCns(request.getParameter(%22cns%22));%0D%0A%09%09paciente.setTipoAtendimento(request.getParameter(%22Tipo de Consulta%22));%0D%0A%09%09paciente.setTelefoneFixo(request.getParameter(%22tel%22));%0D%0A%09%09paciente.setTelefoneCel(request.getParameter(%22celular%22));%0D%0A%0D%0A%09%09dao.alterar(paciente);%0D%0A%09%09List%3CPaciente%3E pacientes = dao.listarPaciente();%0D%0A%09%09request.setAttribute(%22pacientes%22, pacientes);%0D%0A%0D%0A%0D%0A%09%09cf.close();%0D%0A%0D%0A%09%09RequestDispatcher requestDispatcher = request.getRequestDispatcher(%22Listar_Pacientes.jsp%22);%0D%0A%09%09requestDispatcher.forward(request, response);%0D%0A
 %09%09%0D%0A%09%7D%0D%0A

Update upDatePacienteServlet.java v 1.0.1