[英]Dynamically creating a checkbox from an Array list java
I am trying to populate a page with check box selections.I am using struts in my project.So in the action class i have created the list loaded with experiment nos in it.So in My Jsp page i got back the experiment list and set it to the checkbox .But the checkboxes with unique experiment nos are not shown on the page 我试图用复选框选择填充页面。我在我的项目中使用struts.so在动作类中,我创建了一个加载有实验编号的列表。所以在My Jsp页面中,我返回了实验列表并进行设置到复选框。但是带有唯一实验编号的复选框未显示在页面上
Generating the list from the action class 从动作类生成列表
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>
Kindly help on how to display checkbox dynamically.. 请提供有关如何动态显示复选框的帮助。
<c:set var="count" value="0" scope="page" />
<c:forEach var="item" items="${expNos}">
<input type="checkbox" name="${count + 1}" value="${item}"/>
</c:forEach>
update: 更新:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.