- package servlets; 
-   
- import java.io.IOException; 
- import java.sql.ResultSet; 
- import java.sql.SQLException; 
-   
- import javax.servlet.ServletException; 
- import javax.servlet.http.HttpServlet; 
- import javax.servlet.http.HttpServletRequest; 
- import javax.servlet.http.HttpServletResponse; 
-   
- import classes.Conexion; 
-   
- /** 
-  * Servlet implementation class NuevoClienteServlet 
-  */ 
- public class NuevoClienteServlet extends HttpServlet { 
-     private static final long serialVersionUID = 1L; 
-   
-     /** 
-      * @see HttpServlet#HttpServlet() 
-      */ 
-     public NuevoClienteServlet() { 
-         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 
-     } 
-   
-     /** 
-      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 
-      */ 
-     protected void-  doPost (- HttpServletRequest request, HttpServletResponse response ) throws-  ServletException,  IOException {
 
-          
-         Conexion.Inicializar(); 
-         Conexion.Conectar(); 
-   
-         //Carga de campos de la pagina JSP 
-         String-  nombreCliente  =-  request. getParameter("txtNombre")- . trim();
 
-         String-  apellidosCliente  =-  request. getParameter("txtApellidos");
 
-         String-  direccionCliente  =-  request. getParameter("txtDireccion");
 
-         String-  telefonoCliente  =-  request. getParameter("txtTelefono")- . trim();
 
-         String-  emailCliente  =-  request. getParameter("txtEmail")- . trim();
 
-   
-         if (!nombreCliente.isEmpty() ||  
-                 !apellidosCliente.isEmpty() || 
-                 !direccionCliente.isEmpty() || 
-                 !telefonoCliente.isEmpty() || 
-                 !emailCliente.isEmpty()) 
-         { 
-             String-  sqlSentencia  = "INSERT INTO cliente (nomcli, apecli, dircli, telcli, emailcli) VALUES ('" +
 
-             nombreCliente + "' , '" + 
-             apellidosCliente + "' , '" + 
-             direccionCliente  + "' , '" + 
-             telefonoCliente  + "' , '" + 
-             emailCliente  + "')"; 
-   
-             //System.out.println(sqlSentencia); 
-   
-             int errorSQL = Conexion.Actualizacion(sqlSentencia); 
-   
-             if (errorSQL != 1) 
-             { 
-                 System- . out- . println("Error de SQL");
 
-             } 
-             else 
-             { 
-                 System- . out- . println("Registro insertado");
 
-             } 
-         } 
-         else 
-         { 
-             System- . out- . println("Campos vacios");
 
-         } 
-   
-         if (request.getParameter("btnGuardarNuevo")!=null) 
-         { 
-             response.sendRedirect("NuevoCliente.jsp"); 
-         } 
-         else if(request.getParameter("btnGuardar")!=null) 
-         { 
-             try { 
-                 ResultSet-  tabla  =-  Conexion. Consulta("select auto_increment from `information_schema`.tables where TABLE_SCHEMA = 'informatica' and TABLE_NAME = 'cliente'");
 
-   
-                 while (tabla.next()) 
-                 { 
-                     //Restamos uno ya que el codigo que devuelve la consulta es el siguiente 
-                     int codigoCliente = tabla.getInt("auto_increment")-1; 
-                      
-                     String URL = "DetalleCliente.jsp?codCliente=" +-  codigoCliente ;
 
-                      
-                     response. sendRedirect(URL);
-                 } 
-                 // TODO Auto-generated catch block 
-                 e.printStackTrace(); 
-             } 
-         } 
-         Conexion.Cerrar(); 
-     } 
- } 
-