as I filled out a drop-down list in jsp with a mysql servlet query

0

I need to create a drop-down list in jsp with a query made in mysql I am working with mvc attached the servlet where I have the data of the query but I could not send the data to the drop-down list and also attached the jsp page.

Can you tell me how this can be done?

SeleccionarFechasDao dao = new SeleccionarFechasDao();
dao.CargarDatos();
ResultSet res = dao.CargarDatos();

List<GenerarFechas> fechas = new ArrayList<>();

try {
    while (res.next()) {

        /* codigo para agregar fechas */
    }
} catch (SQLException ex) {
    Logger.getLogger(SeleccionarFechas.class.getName())
        .log(Level.SEVERE, null, ex);
}
request.getSession().setAttribute("GenerarFechas", fechas);
request.getRequestDispatcher("consulta.jsp").forward(request, response);

And here is where the mysql query should go in the drop-down list

<label for="Fecha">Fecha</label>
<select type="text" name="Fecha" class="form-control" size="9"
    placeholder="Mes.Año" required="true">
    <!-- options -->
</select>
    
asked by victormbrt 01.03.2017 в 22:33
source

1 answer

1

Inside your JSP code:

<%
    List<GenerarFechas> fechas = request.getSession().get("fechas");
%>

You put here a foreach or a for that runs 'dates'

<% for(GenerarFechas fecha : fechas) { %>
    <option value="<%=fecha.getElMetodoQueTeTraeElID();">
        <%=fecha.getElMetodoQueTeTraeLaFecha(); %>
    </option>
<% } //Cerrar FOR %>

I hope I gave you an idea.

    
answered by 01.03.2017 в 23:43