Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Servlet输出2个向量,使用JSTL在JSP上进行两次选择显示。_Jsp_Vector_Jstl - Fatal编程技术网

Servlet输出2个向量,使用JSTL在JSP上进行两次选择显示。

Servlet输出2个向量,使用JSTL在JSP上进行两次选择显示。,jsp,vector,jstl,Jsp,Vector,Jstl,我试图使用JSTL在jsp中显示servlet中的两个向量。它在/nameofmyfile处传递一个错误。不知道怎么了 我是这样编码的。我的servlet: Vector<Mascotas> masco; Usuario nomu=(Usuario)request.getSession().getAttribute("usuario"); String nomusu=nomu.getUsuario(); try { masco=GestorBD.getInstan

我试图使用JSTL在jsp中显示servlet中的两个向量。它在/nameofmyfile处传递一个错误。不知道怎么了

我是这样编码的。我的servlet:

    Vector<Mascotas> masco;
Usuario nomu=(Usuario)request.getSession().getAttribute("usuario");

String nomusu=nomu.getUsuario();

try {
    masco=GestorBD.getInstance().cargarAni(nomusu);

    request.setAttribute("losanimales", masco);
    RequestDispatcher rd=request.getRequestDispatcher("pedircita.jsp");
    rd.forward(request, response);

} catch (ClassNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (SQLException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}



Vector<Veterinario> vet;

try {
    vet=GestorBD.getInstance().cargarVet();
    request.getSession().setAttribute("los veterinarios",vet);
    //response.sendRedirect("pedircita.jsp");
    RequestDispatcher rd=request.getRequestDispatcher("pedircita.jsp");
    rd.forward(request, response);
} catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}



}
}

这是我的GestorBD数据库

    //To charge beans Veterinarios and Mascotas

public Vector<Veterinario> cargarVet() throws SQLException, ClassNotFoundException {

    Vector<Veterinario> vector= new Vector<Veterinario>();
    Veterinario v=null;

    establecerConexion();

    String sql="SELECT id_vete,nombre_vet,apellidos_vet from veterinarios";
    PreparedStatement pst=conn.prepareStatement(sql);
    ResultSet rs=pst.executeQuery();

    if(rs.next()){

     v=new Veterinario();

     v.setId_vete(rs.getInt("id_vete"));
     v.setNombre_vet(rs.getString("nombre_vet"));
     v.setApellidos_vet(rs.getString("apellidos_vet"));

    vector.add(v);

    }

    cerrarConexion();
    return vector;
}


public Vector<Mascotas> cargarAni(String nomusu) throws SQLException, ClassNotFoundException {

    Vector<Mascotas> vector=new Vector<Mascotas>();
    Mascotas a=new Mascotas();

    establecerConexion();

    String sql="SELECT id_ani,nombre_ani FROM mascotas WHERE nombre_prop=?";

    PreparedStatement pst=conn.prepareStatement(sql);
    ResultSet rs=pst.executeQuery();

    if(rs.next()){

        a= new Mascotas();
        a.setId_animal(rs.getInt("id_ani"));
        a.setNombre_ani(rs.getString("nombre_ani"));

        vector.add(a);


    }
        cerrarConexion();
        return vector;
    }
最后是我的pedircinta.jsp:

    <article>

                <h2>FORMULARIO DE PETICION DE CITAS</h2>


            <form name="formupedircita" id="formupedircita" action="ServletPedirCita" method="post">
    <label>Nombre_propietario :</label><input type="text" name="prop" placeholder="Nombre_propietario" required><br/>
    <label>Nombre_mascota  :</label><select multiple="multiple" name="ani">
                            <c:forEach var="element" items="${losanimales}">
                            <option value="${ element.id_animal}">${element.nombre_ani}</option>
                            </c:forEach>
                            </select>


    <label>Introduzca la fecha de la cita  que desea :*</label><input type="text" name="fecha_cita" value="00-00-2015" required><br/>
    <label>Introduzca hora y minutos:</label><br/>
    Horas
    <select name="hora">

        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
    </select>

    Minutos
    <select name="minutos">
        <option value="1">00:00</option>
        <option value="2">00:30</option>

    </select>


    Introduzca su veterinario:
    <select multiple="multiple" name="veterinario">
        <c:forEach var="element" items="${losveterinarios}">
        <option value="${element.id_vete }">${element.nombre_vet }${element.apellidos.vet }</option>
        </c:forEach>
    </select>

    <input type="submit" name="boton"  class="boton" value="Enviar">

</form>
<a class="boton"id="salir" href="ServletSalir">SALIR</a>
</article>


Could you please give me any suggestion about this matter? Thanks a million

Servlet不能有两个RequestDispatcher,因此如果Servlet以这种方式编码:

 Vector<Mascotas> masco;
 Vector<Veterinarios> vete;
 Usuario nomu=(Usuario)request.getSession().getAttribute("usuario");

 String nomusu=nomu.getUsuario();

try {
    masco=GestorBD.getInstance().cargarAni(nomusu);
    vete=GestorBD.getInstance().cargarVet();
request.setAttribute("losanimales", masco);
request.setAttribute("losveterinarios",vete);
RequestDispatcher rd=request.getRequestDispatcher("pedircita.jsp");
rd.forward(request, response);

} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
de jsp可以通过请求访问两个属性LosAnimales和losveterinarios,它们将显示在屏幕上

希望对别人有帮助