Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops Struts逻辑迭代标记以循环表行_Loops_Html Table_Struts 1 - Fatal编程技术网

Loops Struts逻辑迭代标记以循环表行

Loops Struts逻辑迭代标记以循环表行,loops,html-table,struts-1,Loops,Html Table,Struts 1,我正在使用struts。当每次迭代都使用不同的列表时,如何使用iterate标记来创建一个表行,该表行通过first name和last name进行迭代 <logic:iterate name="fName" id="listMsgId1"> <tr> <td>First Name: <bean:write name="listMsgId1"/></td> <logic:

我正在使用struts。当每次迭代都使用不同的列表时,如何使用iterate标记来创建一个表行,该表行通过first name和last name进行迭代

 <logic:iterate name="fName" id="listMsgId1">
      <tr>
           <td>First Name: <bean:write name="listMsgId1"/></td>
           <logic:iterate name="lName" id="listMsgId2" >
           <td>Last Name: <bean:write name="listMsgId2"/></td>     
           </logic:iterate>     
      </tr>
 </logic:iterate>

名字:
姓氏:
目前我得到的输出是名字:juan姓氏:brown姓氏:smith 名字:肯姓:布朗姓:史密斯


我希望姓氏只为每个名字出现一次,而不是为创建的行显示一次。

在操作中创建一个适当的数据结构,并传递该数据结构,而不是两个列表。

@Dave answer是正确的,尽管这可能对您有所帮助

您应该创建包含两个属性的
ActioForm

public class PersonDetail extends ActionForm 
{
protected String firstName;
protected String lastName;

public void setFirstName(String newFirstName) {
    firstName = newFirstName;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String newLastName) {
    lastName = newLastName;
}

public String getLastName() {
    return lastName;
}
}
现在根据需求进行迭代,假设动作类中的
PersonDetail
ArrayList

<logic:iterate name="PersonDetail" id="listUsers">
     <tr>
          <td>First Name: <bean:write name="listUsers" property="FirstName"/></td>
          <td>Last Name: <bean:write name="listUsers" property="LastName"/></td>
     <tr>
</logic:iterate>

名字:
姓氏:

作为旁注,您可以使用hashmap轻松完成。 在java类中,您将创建一个hashap,代码如下

HashMap<String,String> myMap = new HashMap();
myMap.put("DummyFirstName", "DummyLastName");
myMap.put("raheel","arif");
myMap.put("dave","newton");
request.setAttribute("SubscribedLists", myMap);
HashMap myMap=newhashmap();
myMap.put(“DummyFirstName”、“DummyLastName”);
myMap.put(“raheel”、“arif”);
myMap.put(“dave”、“newton”);
setAttribute(“订阅列表”,myMap);
和jsp页面代码

               <logic:iterate name="SubscribedLists" id="SubscribedListsId">

                        <div>                         
                        <p><bean:write name="SubscribedListsId" property="key"/></p>                             
                        </div>

                        <div>
                          <p><bean:write name="SubscribedListsId" property="value"/></p>
                        </div>
                </logic:iterate>

在我的示例中,我使用了divs,您可以轻松地将其转换为代码表