give values to a drop-down list

0

Hello, I am very new in this, what happens to me is that I have a jsp form that has a drop-down list and when I fill the entire form in the database in that field it saves 0 and I want it to save the value that I assign him. Help please

the profile field is the drop-down list

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

    PrintWriter out = response.getWriter();

    String perfil_r = request.getParameter("perfil_r");
    String nombre_r = request.getParameter("nombre_r");
    String apellido_r = request.getParameter("apellido_r");
    String numeroid = request.getParameter("numeroid");
    String cargo_R = request.getParameter("cargo_R");
    String correo_r = request.getParameter("correo_r");
    String celular_r = request.getParameter("celular_r");
    String nombrecompa_r = request.getParameter("nombrecompa_r");
    String nit_r = request.getParameter("nit_r");
    String direccion_r = request.getParameter("direccion_r");
    String telefono_r = request.getParameter("telefono_r");
    String nombreU_r = request.getParameter("nombreU_r");
    String contraseña_r = request.getParameter("contraseña_r");

    consultas co = new consultas();

    if (co.registrar(nombre_r, correo_r, nombrecompa_r, direccion_r, apellido_r, cargo_R, nombreU_r, contraseña_r, 0, 0, 0, 0)) {
        response.sendRedirect("index.jsp");
     if(perfil_r.equals("1")){
         out.println("GERENCIA");
         }if(perfil_r.equals("2")){
         out.println("CLIENTE");
         }if(perfil_r.equals("3")){
         out.println("EMPLEADO");
         }
    } else {
        response.sendRedirect("MENU.jsp");
    }

public boolean registrar(String NOMBRE_R, String CORREO_R, String NOMBRECOM_R, String DIRECCION_R,
            String APELLIDO_R, String CARGO_R, String ID_NOMBREU, String ID_CONTRASEÑA,
            int PERFIL, int IDENTIICASION_R, int CELULAR, int NIT) {
    PreparedStatement stm = null;
    try {
        String miusuario = "insert into REGISTRO ( PERFIL, NOMBRE_R,IDENTIICASION_R,CORREO_R,NOMBRECOM_R,DIRECCION_R,APELLIDO_R,CARGO_R,CELULAR,NIT,ID_NOMBREU,ID_CONTRASEÑA)values(?,?,?,?,?,?,?,?,?,?,?,?)";
        stm = getConnection().prepareStatement(miusuario);
        stm.setInt(1, PERFIL);
        stm.setString(2, NOMBRE_R);
        stm.setInt(3, IDENTIICASION_R);
        stm.setString(4, CORREO_R);
        stm.setString(5, NOMBRECOM_R);
        stm.setString(6, DIRECCION_R);
        stm.setString(7, APELLIDO_R);
        stm.setString(8, CARGO_R);
        stm.setInt(9, CELULAR);
        stm.setInt(10, NIT);
        stm.setString(11, ID_NOMBREU);
        stm.setString(12, ID_CONTRASEÑA);

        if (stm.executeUpdate() == 1) {
            return true;
        }

    } catch (Exception e) {
        System.err.println("errorrr" + e);
    } finally {
        try {
            if (getConnection() != null) {
                getConnection().close();
            }
            if (stm != null) {
                stm.close();
            }
        } catch (Exception e) {
            System.err.println("errorrr 2" + e);
        }
    }

jsp

<table border="0" align="center">

    <tbody>
        <tr>
            <td colspan="2">Pefil</td>
            <td colspan="2"> <select  name="perfil_r" id="perfil_r" required="required"> 
                    <option id="1" value="1" >GERENCIA</option>
                    <option id="2" value="2"> CLIENTE</option>
                    <option id="3" value="3" > EMPEADO</option>

                </select> </td>

 

    
asked by luisa suaza 23.05.2018 в 17:47
source

1 answer

0

First of all, all option of a select , must have its closing tag, <option value="1">Es uno</option> .

Where you are calling the registering method, you are not sending the captured item to the drop-down list.

co.registrar(nombre_r, correo_r, nombrecompa_r, 
direccion_r, apellido_r, cargo_R, nombreU_r, contraseña_r, 
0, //aquí es donde debería ir la variable que carga el valor del select
0, 0, 0)

Like this:

co.registrar(nombre_r, correo_r, nombrecompa_r, 
    direccion_r, apellido_r, cargo_R, nombreU_r, contraseña_r, 
    perfil_r, //aquí va la variable
    0, 0, 0)

And apparently it needs the other data too.

    
answered by 24.05.2018 в 01:06