go through a list in jsp

1

I have a result saved in a list, the list is passed to a jsp by means of a servlet, with that list filled with a select and depending on that select (name = nomFuent) an input must be completed (name="nitfuente "), how can I do it.

servlet

String Numasociado = request.getParameter("nitbuscar");
             Consultas con = new Consultas();

             List <NumRecibo> lista = con.cosulFuentesAsociado(Numasociado);


          request.setAttribute("listado", lista);
          request.getRequestDispatcher("/ingreso.jsp").forward(request, response)

;

jsp 



 <%-- 
        Document   : ingreso
        Created on : 20/07/2016, 12:59:42 PM
        Author     : jefma
    --%>


    <%@page import="Controlador.NumRecibo"%>
    <%@page import="java.util.List"%>
    <%@page import="java.util.ArrayList"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <!DOCTYPE html>

    <html>
        <head>
            <meta charset="utf-8"/>
            <link rel="icon" type="image/png" href="resource/img/index.ico"/>
            <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
            <meta name="viewport" content="width=device-width, initial-scale=1"/>
            <title>Generar Recibo</title>
            <link href="resource/css/bootstrap.min.css" rel="stylesheet"/>
            <link href="resource/css/main.css" rel="stylesheet"/>
            <script src="resource/js/jquery-2.1.1.min.js"></script>
            <script src="resource/js/bootstrap.js"></script>
            <script src="resource/js/main.js"></script>
        </head>
        <body>
            <%!  int contador = 2;%>
            <div class = "container">
                <div  class="page-header page-header2 text-left">
                    <img src="resource/img/logo.png" class="img-responsive " alt="Responsive image"/>
                </div>

                <div class="col-md-12 ">
                    <div class="text-right col-md-7 ">
                        <h3 class="media-heading colorsub"><b>Generar Ingreso</b> </h3>
                    </div>
                    <div class="text-right col-md-5 ">
                        <button class="btn btn-default btn-defaul btn-primary2 " type="button" onclick="history.back()">Regresar</button>
                    </div>
                </div>
                <div class="col-sm-12" style = "margin-top:120px">


                    <div class="col-md-12 ">
                        <div class="col-md-3 ">
                            <label  class="control-label ">Razon social:</label>
                            <select  id="nomFuent" name="nomFuent" class="form-control"required >
                                <option> </option>  
                                <%
                                    List<NumRecibo> lista = (List<NumRecibo>) request.getAttribute("listado");

                                    int i = 0;
                                    for (NumRecibo numRecibo : lista) {

                                        String nombrefuente = (numRecibo.getNombre());
                                        out.println("<option value=" + nombrefuente + ">" + nombrefuente + "</option>");
                                    }

                                %>


                            </select>    
                        </div>
                        <div class="col-md-3 ">
                            <label  class="control-label  ">Nit Fuente:</label>

                            <% for (NumRecibo numRecibo : lista) {
                                    i++;
                                    int t = lista.size();

                                    int con = contador;
                           if (con == i) {
                               String nit = (numRecibo.getNit());%>
                            <input type="inputtext" class="form-control" id="nit" placeholder="NIT" value="<%=nit%>" disabled="disabled" name="nitfuente" />
                            <%}
                                if (i == t) {
                                    String nitA = (numRecibo.getNitAsociado());
                                    String nom = (numRecibo.getNomAsociado());
                            %>

                        </div>
                        <div class="col-md-3 ">
                            <label  class="control-label  ">Nit Asociado:</label>         

                            <input type="inputtext" class="form-control" id="nit" placeholder="NIT" value="<%=nitA%>" disabled="disabled"  />
                        </div>
                        <div class="col-md-3 ">
                            <label  class="control-label ">Nombre Asociado:</label>
                            <input type="text" class="form-control" id="Razonsocial" placeholder="Razon social" value="<%=nom%>"disabled="disabled">
                        </div><%}
                            }%>
                    </div>
                </div>
                <div class="col-sm-12" style = "margin-top:120px">

                    <table id="tablaMateriales" class="table table-bordered" >
                        <thead>

                            <tr>
                                <th rowspan="2" scope="col">No</th>

                                <th rowspan="2" scope="col ">Clase Residuo</th>
                                <th rowspan="2" scope="col">Tipo Residuo</th>
                                <th rowspan="2" scope="col">Cantida Kilos</th>
                                <th rowspan="2" scope="col">Valor Unitario</th>
                                <th rowspan="2" scope="col">Valor Total</th>


                                <th colspan="2" scope="col">Rechazo</th>
                            </tr>

                            <tr> 
                                <th scope="col"  >Kilos</th>
                                <th scope="col">Valor</th>

                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="col-sm-1 ">1</td>
                                <td class="col-sm-2 "><select id="tipomaterial" name="tipomaterial" class="form-control ">
                                        <option value="0" selected="selected"> </option>
                                        <option value="M" >Metales </option>
                                        <option value="PC" >Papel-Carton</option>
                                        <option value="PL" >Plasticos</option>
                                        <option value="V" >Vidrio</option>
                                        <option value="R" >Reuso</option>
                                        <option value="RE" >Retoma</option>

                                    </select></td>
                                <td class="col-sm-2 "><select id="tiporesiduo" name="tiporesiduo" class="form-control ">

                                    </select></td></td>
                                <td class="col-sm-1 "><input type="text" class="form-control"></td>
                                <td class="col-sm-1 "><input type="text" class="form-control"></td>
                                <td class="col-sm-2 "><input type="text" class="form-control"></td>
                                <td class="col-sm-1 "><input type="text" class="form-control"></td>
                                <td class="col-sm-2 "><input type="text" class="form-control"></td>
                                <td class="text-center">

                            </tr>
                        </tbody>    
                    </table>
                    <table id ="tablatotales" class="table table-bordered table-responsive " >   

                        <tr>
                            <td class="col-sm-1">
                            </td>
                            <td class="col-sm-5">
                            </td>
                            <td class="col-sm-2 active col colorstit">
                                Sub Total 
                            </td>
                            <td class="col-sm-2 active col">
                            </td>
                        </tr>
                        <tr>
                            <td class="col-sm-1">
                            </td>
                            <td class="col-sm-5">
                            </td>
                            <td class="col-sm-2 active col colorstit">
                                IVA 
                            </td>
                            <td class="col-sm-2 active col">
                            </td>
                        </tr>
                        <tr>
                            <td  class="col-sm-1">
                            </td>
                            <td class="col-sm-5">
                            </td>
                            <td  class="col-sm-2 active col colorstit">
                                Total 
                            </td>
                            <td class="col-sm-2 active col">
                            </td>
                        </tr>
                    </table>
                    <div class= "tamanobotton btn btn-primary btn-defaul" id="btnnuevo">Nuevo</div>
                </div>



                <div class="col-md-12 ">
                    <div  class="page-header text-center page-header2">
                        <img src="resource/img/logo2.jpg" class="img-responsive center-block" alt="Responsive image"/>
                    </div>
                </div>
            </div>
        </form>
    </body>  

    </html> 
    
asked by Jeferson Martinez 16.08.2016 в 07:19
source

1 answer

1

what I did was a function with jquery that redirects me to another jsp that executes the query to the bd and returns the result of the query within the same function

jsp

<label  class="control-label  ">Nit Fuente:</label>
                        <input type="hidden" name="i_opc" id="i_opc">
                        <select id="nitfuentes" name="nitfuente" class="form-control"required >
                            <option value="">seleccione</option>
                        </select>

jquery

$("select[name=nomFuent]").change(function(){
    $("#f_opc").val("1");
    $.post("combo.jsp",$("#ingresom").serialize(),function(data){$("#nitfuentes").html(data);});

        });

2jsp

    <%@page import="java.sql.*"%>
<%@page import="modelo.Consultas"%>
<%String nom= request.getParameter("nomFuent");%>


<% String co = "SELECT * FROM 'fuentes' WHERE 'nom_Fuente' = '"+nom+"' ORDER BY 'contacto_fuente'" ;
Consultas con = new Consultas();
String nit = con.nitfuentes(co);
System.out.print(nit);
%>
<select name="nitfuentes" >
    <option value="<%=nit%> "> <%=nit%></option>                              
                        </select>
    
answered by 16.08.2016 в 22:03