我在動作類中有一個數組列表。我想在我的jsp頁面以及複選框中訪問這個數組列表。如果複選框被選中,我想在另一個actionclass中獲得複選框的關聯值。我怎樣才能做到這一點??在struts中使用複選框和arraylist 2
Action類:
public class CreateModuleAction extends ActionSupport{
private List modNameList=new ArrayList();
private int size;
public String manageModule()
{
ManageModule ob=new ManageModule();
modNameList=ob.selectModule();
if(modNameList.isEmpty()) {
addActionError("Module list is empty!!!");
return ERROR;
}
else{
setSize(modNameList.size());
return SUCCESS;
}
}
public List getModNameList() {
return modNameList;
}
public void setModNameList(List modNameList) {
this.modNameList = modNameList;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
jsp頁面:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<title>Admin Module Management</title>
</head>
<body>
<div class="main">
<div class="header">
<!-- Page heading-->
<jsp:include page="/templates/heading.jsp" flush="true"/>
</div>
<div class="menu">
<!-- Page menu-->
<jsp:include page="/templates/menu.jsp" flush="true"/>
</div>
<div class="content">
<!-- page content-->
<div id="right_top" style="position:absolute; left:900px; top:300px;;">
<a href="adminCreateModule.jsp"><img src="../images/add.jpg"/>Add</a>
<a href="adminEditModule.jsp"><img src="../images/edit.jpg"/>Edit</a>
<a href="adminDeleteModule.jsp"><img src="../images/add.jpg"/>Delete</a>
</div>
<s:iterator status="size" value="modNameList">
<s:checkbox name="modNameCheck" fieldValue="true" value="modNameList"/>
<s:property value="modNameList"/>
</s:iterator>
<s:actionerror/>
</div>
<div class="footer" style="margin-left: 50%">
<!-- page footer-->
<jsp:include page="/templates/footer.jsp" flush="true"/>
</div>
</div>
</body>
</html>
你嘗試過什麼嗎? – sunleo
我會添加一些我試過的代碼 – user1776488