help Servlet sending parameters

0

I'm trying to get the value that it picks me up from the session started, I listed the students in this table but I do not know how to capture that value captures it in value but how do I capture it in the servlet? already try the name="nIdeEmpresa" but it returns null

    
asked by Jorge Cabrera 24.05.2018 в 03:38
source

2 answers

-2

Send the parameter on the previous page

<a href="ClienteController?metodo=lista&nIdeEmpresa=<%=loginDTO.getnIdeArea()%>">Listar Clientes</a>

and receive it in servlet

    
answered by 25.05.2018 / 13:30
source
0

According to I see there are several things that you can validate that can prevent the recovery of the data: The first thing to try is to use a request and not an arrayList that would be the proper way to retrieve the data from the view jsp

I'll give you an example:

    //Recuperacion Id empresa 
    int empresa = Integer.parseInt(request.getParameter( "nIdeEmpresa" ));


    // Se instancia los recursos del modelo y se da respuesta al request
    // en esta parte validas el null (PARA ESTE CASO NO LO HAGO)
                     ClienteServise sr = new ClienteServise( );
                     ResultSet lista = sr.listaClienteServive( empresa );

   // Se guarda el resultado de la operación No es necesario el list si no lo vas a tratar en el  mismo servlet
   // Instancia un Request para re-dirigir la data
                  request.setAttribute( "lista", lista );


        // Redirecciona el flujo de ejecución hacia la vista jsp
        RequestDispatcher vista = request.getRequestDispatcher( "listaClienteEmpresa.jsp" );
        vista.forward(request, response);  

In your view jsp you read the request that would be the appropriate way to read the data brought from the query.

In this example:

            <%            
 //          <!--MOSTRAR LA CONSULTA  DE  BD-->
  ResultSet lista = (ResultSet)request.getAttribute( "lista" );
  if(lista != null){
      if( lista.first())
      {
          lista.beforeFirst();
              out.println("<br /><br />"
              + "<form method='post' action=''>"
              + "<div style='overflow:auto' id='table_wrapper'>"
              + "<table border ='2px' align='center' id='list'>"
              + "<caption align='center'> LISTADO CLEINTES </caption>"
              + "<thead>"        
              + "<tr>"                                                      
              + "<th>CLIENTE</th>" 
              + "<th>ID CLIENTE</th>"
              + "<th>DIRECCION</th>"
              + "</tr>"
              + "</thead>"); 

        while( lista.next( ) ){



            out.println("<tr>"
                    + "<td >" + lista.getString( 1 ) + "</td>"
                    + "<td >" + lista.getString( 2 ) + "</td>"
                    + "<td >" + lista.getString( 3 ) + "</td>");  
        } 


        out.println("</table>");
        out.println("</div>");
        out.println("</form>");
     %>
  
    

It would be nice if you copied the code to do tests; the images make it difficult to make the exact examples.

  

Greetings!

    
answered by 12.08.2018 в 21:41