0

我正在尝试使用复选框选择填充页面。我在我的项目中使用 struts。所以在动作类中,我创建了加载了实验编号的列表。所以在我的 Jsp 页面中,我取回了实验列表并设置它到复选框。但是具有唯一实验编号的复选框未显示在页面上

从动作类生成列表

public List expList() throws FISException
    {
        Utilities utilities = new Utilities();

        PreparedStatement sqlQueryStmt = null;
        ResultSet resultSet = null;
        int index = 1;
        List expList = new ArrayList();
        Connection conn = null;
        Logger logger = Logger.getInstance();
        try
        {
            String resource = null;
            String sql = "SELECT factory_node_id,exp_id FROM s_exp where dept = ?";
            sqlQueryStmt = conn.prepareStatement(sql);
            sqlQueryStmt.setString(index++,dept);
            resultSet = sqlQueryStmt.executeQuery();
            while(resultSet.next())
            {
                expNo= resultSet.getString(2);
                expList.add(expNo);
            }
        }
        catch(Exception e)
        {
            logger.error(Logger.FLOW,"Error in getting expNo",e);
        }
        finally
        {
            DBUtils.cleanUp(sqlQueryStmt,resultSet);    
            DBUtils.cleanUp(conn);  
        }
        return expList;
    }

<% 
        List expList = new ArrayList();
        expList =factory.getList("resource_list_data");
        request.setAttribute("expNos ", expList );
   %>


 <c:forEach var="item" items="${expNos}">
    <input type="checkbox"  value="${item}"/>
  </c:forEach>  

请帮助如何动态显示复选框..

4

1 回答 1

1
<c:set var="count" value="0" scope="page" />

 <c:forEach var="item" items="${expNos}">
    <input type="checkbox" name="${count + 1}"  value="${item}"/>
  </c:forEach> 

更新:

<c:set var="count" value="0" scope="page" />

 <c:forEach var="item" items="${expNos}">
   ${item}  <input type="checkbox" name="${count + 1}"  value="${item}"/>
  </c:forEach> 
于 2013-07-01T05:51:51.850 回答