0

我试图specialities从一个名为getAllSpecialities()(在内部MedicBean)的函数中获取一些并将它们存储在一个名为specialitiesList. 这个函数返回一个ArrayListofStrings并且它工作正常,它返回所有的特长,问题出在 jsp 中。我不知道为什么, varspecialitiesList没有被填充,它只是null,所以我不能遍历它来填充select.

这就是我一直在尝试做的事情:

<select>
    <option value="" disabled selected>Select an speciality</option>
    <jsp:useBean id="medicAux" class="Model.MedicBean"/>
    <c:set var="specialitiesList" value="${medicAux.allSpecialities}"/>
    <c:forEach items="${specialitiesList}" var="speciality">
        <option value="${speciality}">${speciality}</option>
    </c:forEach>
</select>

这是getAllSpecialities()方法:

public ArrayList<String> getAllSpecialities(){

    ResultSet rs = null;
    Connection conn = null;
    PreparedStatement ps = null;

    ArrayList<String> specialities = new ArrayList<>();

    try {
        conn = Conexion.conectar();

        String query = "SELECT DISTINCT SPECIALITY FROM MEDICO";  
        ps = conn.prepareStatement(query); // create a statement

        rs = ps.executeQuery();

        while (rs.next()) {

            specialities.add(rs.getString("speciality"));
        }
    } catch (SQLException ex) {
        Logger.getLogger(MedicoBean.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("error: "+ex.getMessage());
    }

    Conexion.desconectar(conn);

    return specialities;
}`

我究竟做错了什么?如果您需要一些额外的信息,请索取。谢谢!

4

0 回答 0