从Arraylist java动态创建复选框

时间:2013-07-01 05:47:42

标签: java javascript html struts2

我正在尝试使用复选框选择填充页面。我在我的项目中使用struts。所以在动作类中,我创建了在其中加载了实验nos的列表。所以在My 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>  

请帮助我们动态显示复选框..

1 个答案:

答案 0 :(得分: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>