如何在Bean对象的<c:foreach>循环中使用<c:set>?

时间:2016-06-02 16:15:42

标签: javascript java jsp jstl

我真的很可能会帮助你。我需要使用JSTL c:set标记或JavaScript将用户的输入发回服务器。我有servlet名为StarTeamServer,其中ArrayListUserAccessDetailObject个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>

0 个答案:

没有答案