我真的很可能会帮助你。我需要使用
JSTL c:set
标记或
JavaScript
将用户的输入发回服务器。我有
servlet
名为
StarTeamServer
,其中
ArrayList
有
UserAccessDetailObject
个bean。
JSP
显示
ArrayList
表格结果正常,但我不知道如何对
c:set
索引
forEach
上的
loop
进行编码。我希望你能提供一些例子来帮助..
//Servlet where I load ArrayList and add it into session scope
public class StarTeamServer{
private ArrayList<UserAccessDetailObject> requestedUsersSecurityAccessDetailObjectList = new ArrayList<UserAccessDetailObject>();
public ArrayList<UserAccessDetailObject> getRequestedUsersSecurityAccessDetailObjectList() {
ect...
}
public void setRequestedUsersSecurityAccessDetailObjectList(
ect...
}
ect...
session.setAttribute("STServerBean", stServer);
}
//A bean object that is stored in Array
public class UserAccessDetailObject {
private String serverName = "";
private String serverPort = "";
private String serverProjectName = "";
public String getServerName() {
return serverName;
}
public void setServerName(String serverName) {
this.serverName = serverName;
}
ect ..........
}
//JSP using JSTL forEach loop is working to display data from the server in the JSP.
<Form method="post" name="formToSubmit" id="formToSubmit" action="ControllerSubmitRequest" enctype="multipart/form-data">
<jsp:useBean id="STServerBean" type="com.bis.alm.model.StarTeamServer" class="com.bis.alm.model.StarTeamServer" scope="session" />
<c:forEach var="userAccessDetailObject" items="${STServerBean.requestedUsersSecurityAccessDetailObjectList}" varStatus="theCount">
<tr>
<td><input type="text" name="serverNameID_${theCount.count}" value="${userAccessDetailObject.serverName}" /></td>
<td><input type="text" name="serverPortID_${theCount.count}" value="${userAccessDetailObject.serverPort}" /></td>
<td><c:out value="${theCount.count}"></c:out></td>
</tr>
</c:forEach>