How to redirect a jsp page to another with servlets in java

0

Good, my problem is that I have an error in the handling of servlets and I do not know the cause, I am working with servlets, and from "index.jsp" to "egresado.jsp" it works great, but there, when the client does some process to save in the database, I want to go to a servlet, register, and return to the same "egresado.jsp" .. He registers me in the database, but he does not show me the page "graduated .jsp. " The error and the code fragment on the graduate page, are the following: Thank you very much in advance.

This is the code of the doPost, of the servlet.

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();  

    String codAlumno = request.getParameter("cod_alumno_registrar");
    String idFormacion = request.getParameter("id_formacion_registrar");
    String tipoFormacion = request.getParameter("tipo_continua_registrar");
    String institucion = request.getParameter("nom_institucion_registrar");
    String departamento="";
    int numMunicipio=0;
    String pais= request.getParameter("pais_registrar");

    if(pais.equalsIgnoreCase("COL")){
        departamento = request.getParameter("departamento_registrar");
        numMunicipio = Integer.parseInt(request.getParameter("municipio_registrar"));
    }else{
        departamento=null;
    }
    String intAlta=request.getParameter("optAlta");
    String intBaja=request.getParameter("optBaja");
    String intMedia=request.getParameter("optMeMia");
    String intensidad="";
    if(intAlta!=null && intAlta.equals("on")){
        intensidad="AL";
    }else if(intBaja!=null && intBaja.equals("on")){
        intensidad="BA";
    }else if(intMedia!=null && intMedia.equals("on")){
        intensidad="ME";
    }else{
        intensidad=null;
    }

    String fechaInicio= request.getParameter("fecha_inicio_registrar");
    String fechaFin = request.getParameter("fecha_terminacion_registrar");
    String fechaTitulo = request.getParameter("fecha_titulo_registrar");
    String fechaRegistro = request.getParameter("fecha_registro_registrar");

    //FECHAS actual
    Calendar fecha = Calendar.getInstance();
    int dia = fecha.get(Calendar.DAY_OF_MONTH);
    int mes = fecha.get(Calendar.MONTH);
    int anio = fecha.get(Calendar.YEAR);


    if(fechaInicio.equals("")){
        fechaInicio = (anio+"-"+mes+"-"+dia);
    }

    if(fechaFin.equals("")){
        fechaFin = (anio+"-"+mes+"-"+dia);
    }


    if(fechaTitulo.equals("")){
        fechaTitulo = (anio+"-"+mes+"-"+dia);
    }


    if(fechaRegistro.equals("")){
        fechaRegistro = (anio+"-"+mes+"-"+dia);
    }


    String usuarioRegistro = request.getParameter("nom_usuario_registrar");


    FormacionContinuaDTO g=new FormacionContinuaDTO();

    g.setId(Integer.parseInt(idFormacion));
    g.setCodalumno("1151124");
    g.setTipocontinua(tipoFormacion);
    g.setInstitucion(institucion);
    g.setPais(pais);
    g.setDepartamento(departamento);
    g.setMunicipio(numMunicipio);
    g.setIntencidad(intensidad);
    g.setFechainicio(Date.valueOf(fechaInicio));
    g.setFechaterminacion(Date.valueOf(fechaFin));
    g.setFechatitulo(Date.valueOf(fechaTitulo));
    g.setFecharegistro(Date.valueOf(fechaRegistro));    
    g.setUsarioregistro(usuarioRegistro);


    ObjetoDAO dao= new ObjetoDAO(false);
    try{

    boolean x=dao.insertarFormacionContinua(g);

    if(x) {
           out.print("Correcto!");  

    request.getRequestDispatcher("/egresado.jsp").forward(request, response);
    //              
    request.getRequestDispatcher("/egresado.jsp").include(request, response);

    } else {
        out.print("Incorrecto!");  
      //            RequestDispatcher 
      rd=request.getRequestDispatcher("/egresado.jsp");  
      //            rd.include(request, response);  
        request.getRequestDispatcher("/egresado.jsp").forward(request, response);
    }



    }catch(Exception e){
        e.getMessage();
    }







}
    
asked by Gerson Guerrero 05.06.2017 в 22:56
source

0 answers