SaveServlet.java 1.35 KB
Newer Older
1 2 3 4
package com.roshka.proyectofinal.profesor;

import com.roshka.proyectofinal.entity.Profesor;
import jakarta.servlet.ServletException;
5
import jakarta.servlet.annotation.WebServlet;
6 7 8 9 10 11 12
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

13
@WebServlet("/SaveServletProfesor")
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
public class SaveServlet extends HttpServlet {
    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");
        String email=request.getParameter("correo");
        String nro_cedulaStr=request.getParameter("nro_cedula");
        int nro_cedula = Integer.parseInt(nro_cedulaStr);
        Profesor p =new Profesor(nro_cedula, nombre, apellido, email);

        int status=ProfesorDao.save(p);
        if(status>0){
            out.print("<p>Record saved successfully!</p>");
30
            request.getRequestDispatcher("formulario_profesor.jsp").include(request, response);
31 32 33 34 35 36 37 38
        }else{
            out.println("Sorry! unable to save record");
        }

        out.close();
    }

}