logic:iterate里面的id和name写什么,对应哪里:
<table bgcolor="#ff80ff" border="1">
<tr>
<th>工号</th>
<th>姓名</th>
<th>工作</th>
<th>年限</th>
<th>工资</th>
</tr>
<logic:iterate id="emp" name="list">
<td><bean:write name="emp" property="Empno"/></td>
<td><bean:write name="emp" property="Ename"/></td>
<td><bean:write name="emp" property="Job"/></td>
<td><bean:write name="emp" property="Hiredate"/></td>
<td><bean:write name="emp" property="Sal"/></td>
</logic:iterate>
</table>
-------------------------------------------
- <logic:iterate id="emp" name="list">
name属性:是你放置Bean的集合,在你的这段代码中:
- public class QueryAction extends Action {
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- EmpDao empDao = new EmpDao();
- ArrayList list = empDao.empName();
- //System.out.println(list);
- request.setAttribute("list", list);
- return new ActionForward("/display.jsp");
- }
- }
- request.setAttribute("list", list);
- request.setAttribute("myList", list);
logic:iterator中的id属性,其实是你要从你的集合中取出的Bean的名字,这个名字是任意起的,主要是下面的<bean:write name="emp" property="Ename"/>标签中的name属性要跟logic:iterator中的id属性对应上.其实这里的是这样的,首先<logic:iterator>标签会把name属性值为list的集合里的bean逐一取出来,每取出来一个,就把他存到名为id属性的值的pageContext范围内,一看代码你就能明白:
主要代码:
- //首先取出List,getAttribute()方法中的值就是<logic:iterator>标签的name
- //值
- List list=request.getAttribute("list");
- //然后把取出来的bean存入pageContext范围内,对应的名字就是id的值
- pageContext.setAttribute("emp",bean);
- //<bean:write>标签其实就是利用反射把Bean从相应的范围内取出
- pageContext.getAttribute("emp");