Database 用数据库中的值填充jsp下拉菜单

Database 用数据库中的值填充jsp下拉菜单,database,jsp,servlets,Database,Jsp,Servlets,如何用数据库中的值填充JSP中的下拉菜单(遵循MVC体系结构)? 我试过这么做 在…内 EmployeeDAO.java private List<EmployeeVO> empIDList; public List<EmployeeVO> getStateList(){ empIDList=new ArrayList<EmployeeVO>(); Connection con=DBUtil.getConnection

如何用数据库中的值填充JSP中的下拉菜单(遵循MVC体系结构)? 我试过这么做 在…内 EmployeeDAO.java

private List<EmployeeVO> empIDList;

    public List<EmployeeVO> getStateList(){
        empIDList=new ArrayList<EmployeeVO>();
        Connection con=DBUtil.getConnection();



        try {
            Statement stmt=con.createStatement();
            ResultSet rs=stmt.executeQuery("select Emp_id from Employee order by Emp_id ASC");
            while(rs.next()){
                String emID=rs.getString("Emp_id");
                int empID=Integer.parseInt(emID);
                EmployeeVO s=new EmployeeVO();
                s.setEmp_id(empID); 
                empIDList.add(s);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        return empIDList;
    }
里面 Employee.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:useBean id="emplID" scope="session" class="com.model.EmployeeVO" />

<th>Employee ID</th>
                    <td><input type="text" name="EID" id="eid" /> 
                    <select
                        id="testlist">
                            <c:forEach var="item" items="${emplID.items}">
                                <option>${item}</option>
                            </c:forEach>
                    </select> 
                    </td>

员工ID
${item}

jsp的源代码取自第

页,或许您可以尝试此
Vector
arraylist
方法

jsp部分(矢量)

html部分

---请选择---

请尝试引用此问题,谢谢您的帮助。因为在JSP中使用Scriptlet会影响性能。我们如何使用MVC实现这一点?
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<jsp:useBean id="emplID" scope="session" class="com.model.EmployeeVO" />

<th>Employee ID</th>
                    <td><input type="text" name="EID" id="eid" /> 
                    <select
                        id="testlist">
                            <c:forEach var="item" items="${emplID.items}">
                                <option>${item}</option>
                            </c:forEach>
                    </select> 
                    </td>
<%
  Vector vFRUIT_CODE    = new Vector();
  Vector vFRUIT_DESCP   = new Vector();

  String SQL = "SELECT * FROM TB_TEST";
  DB_TEST.makeConnection();
  DB_TEST.executeQuery(SQL);
  while(DB_TEST.getNextQuery())
  {
           String sCODE    = DB_TEST.getColumnString("FRUIT_CODE");
           String sDESCP   = DB_TEST.getColumnString("FRUIT_DESCP");

          vFRUIT_CODE.addElement(sCODE);
          vFRUIT_DESCP.addElement(sDESCP);
  }
  DB_TEST.takeDown();
%>
<select name="FRUIT">
<option value="">--- Please Select ---</option>
<%
    for (int i=0;i<vFRUIT_CODE.size();i++) {
          String sCODE = (String) vFRUIT_CODE.elementAt(i);
          String sDESCP = (String) vFRUIT_DESCP.elementAt(i);
 %>      
<option value="<%=sCODE %>" ><%= sDESCP %></option>
<%}%>  
</select>