From 644d0014cc8d8dfc4b6d7498aef5e3725bb869f7 Mon Sep 17 00:00:00 2001 From: Yovan Martinez Date: Wed, 11 May 2022 17:24:36 -0400 Subject: [PATCH] Editado formulario, creacion de postulanteDao,SaveServlet,correccion errores Postulante --- src/main/java/Postulante/PostulanteDao.java | 14 +++----------- src/main/java/Postulante/SaveServlet.java | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/entity/Postulante.java | 2 +- src/main/webapp/formulario.html | 10 +++++----- 4 files changed, 73 insertions(+), 17 deletions(-) create mode 100644 src/main/java/Postulante/SaveServlet.java diff --git a/src/main/java/Postulante/PostulanteDao.java b/src/main/java/Postulante/PostulanteDao.java index fc3b48a..b0172b9 100644 --- a/src/main/java/Postulante/PostulanteDao.java +++ b/src/main/java/Postulante/PostulanteDao.java @@ -1,4 +1,5 @@ package Postulante; +import com.roshka.proyectofinal.DataBase; import com.roshka.proyectofinal.Postulante; import java.util.*; @@ -6,18 +7,11 @@ import java.sql.*; public class PostulanteDao { - public static Connection getConnection(){ - Connection con=null; - try{ - Class.forName("oracle.jdbc.driver.OracleDriver"); - con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); - }catch(Exception e){System.out.println(e);} - return con; - } + public static int save(Postulante postulante){ int status=0; try{ - Connection con=PostulanteDao.getConnection(); + Connection con= DataBase.getConnection(); PreparedStatement ps=con.prepareStatement( "insert into postulante(nombre,apellido,nro_cedula,correo,telefono,direccion,experiencia_laboral,estudio_universitario,notebook,bootcamp_id,aceptado) values (?,?,?,?,?,?,?,?,?,?,?)"); ps.setString(1,postulante.getNombre()); @@ -31,9 +25,7 @@ public class PostulanteDao { ps.setBoolean(9,postulante.getNotebook()); ps.setInt(10,postulante.getBootcampId()); ps.setBoolean(11,postulante.getAceptado()); - status=ps.executeUpdate(); - con.close(); }catch(Exception ex){ex.printStackTrace();} diff --git a/src/main/java/Postulante/SaveServlet.java b/src/main/java/Postulante/SaveServlet.java new file mode 100644 index 0000000..20051b8 --- /dev/null +++ b/src/main/java/Postulante/SaveServlet.java @@ -0,0 +1,64 @@ +package Postulante; +import com.roshka.proyectofinal.Postulante; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + + +@WebServlet("/SaveServlet") +public class SaveServlet { + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html"); + PrintWriter out=response.getWriter(); + + String nombre=request.getParameter("nombre"); + String apellido=request.getParameter("apellido"); + int cedula=Integer.parseInt(request.getParameter("cedula")); + String correo=request.getParameter("correo"); + String telefono=request.getParameter("telefono"); + String direccion=request.getParameter("direccion"); + boolean experienciaProgramando = false; + boolean experienciaLaboral = false; + boolean universidad = false; + if (request.getParameter("experiencia_laboral") != null){ + experienciaLaboral = true; + } + if (request.getParameter("experiencia_programando") != null) { + experienciaProgramando = true; + } + if (request.getParameter("notebook") != null){ + boolean notebook = true; + } + if (request.getParameter("universidad") != null){ + universidad = true; + } + + + Postulante postulante=new Postulante(); + postulante.setNombre(nombre); + postulante.setApellido(apellido); + postulante.setNro_cedula(cedula); + postulante.setCorreo(correo); + postulante.setTelefono(telefono); + postulante.setDireccion(direccion); + postulante.setExpLaboral(experienciaLaboral); + postulante.setEstudioUniversitario(universidad); + + int status=PostulanteDao.save(postulante); + + + + if(status>0){ + out.print("

Record saved successfully!

"); + request.getRequestDispatcher("index.html").include(request, response); + }else{ + out.println("Sorry! unable to save record"); + } + + out.close(); + } +} diff --git a/src/main/java/entity/Postulante.java b/src/main/java/entity/Postulante.java index 0a03481..0e629a6 100644 --- a/src/main/java/entity/Postulante.java +++ b/src/main/java/entity/Postulante.java @@ -38,7 +38,7 @@ public class Postulante { public String getNombre() { return nombre; } - public void setName(String name) { + public void setNombre(String name) { this.nombre = name; } public String getApellido() { diff --git a/src/main/webapp/formulario.html b/src/main/webapp/formulario.html index 1e2c9eb..359d3cb 100644 --- a/src/main/webapp/formulario.html +++ b/src/main/webapp/formulario.html @@ -18,8 +18,8 @@
- -
+ +

@@ -36,13 +36,13 @@
- -
-
+ +
+
-- libgit2 0.26.0