<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>
</body>
--------------------------------------------------------------------------------------------------
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");
}
}
- <logic:iterate id="emp" name="list">
<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();
-
- request.setAttribute("list", list);
-
- return new ActionForward("/display.jsp");
- }
- }
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("list", list);
你是将list放入到request范围内,对应的名字是list,如果你要是写成
- request.setAttribute("myList", list);
request.setAttribute("myList", list);
,那么,logic:iterator中的name属性就要为"myList".
logic:iterator中的id属性,其实是你要从你的集合中取出的Bean的名字,这个名字是任意起的,主要是下面的<bean:write name="emp" property="Ename"/>标签中的name属性要跟logic:iterator中的id属性对应上.其实这里的是这样的,首先<logic:iterator>标签会把name属性值为list的集合里的bean逐一取出来,每取出来一个,就把他存到名为id属性的值的pageContext范围内,一看代码你就能明白:
主要代码:
-
-
- List list=request.getAttribute("list");
-
- pageContext.setAttribute("emp",bean);
-
- pageContext.getAttribute("emp");