SaveServlet.java 1.36 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
public class SaveServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html");
Angel Zarate committed
18
        PrintWriter out = response.getWriter();
19

Angel Zarate committed
20 21 22 23
        String nombre = request.getParameter("nombre");
        String apellido = request.getParameter("apellido");
        String email = request.getParameter("correo");
        String nro_cedulaStr = request.getParameter("nro_cedula");
24
        int nro_cedula = Integer.parseInt(nro_cedulaStr);
Angel Zarate committed
25
        Profesor p = new Profesor(nro_cedula, nombre, apellido, email);
26

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

        out.close();
    }

}