遍历list
ListAction
private Map<String,Object> request; StuffDao sd=new StuffDaoImp(); @Override public String execute() throws Exception { List<Stuff> stuffs=sd.list(); request.put("list", stuffs); return SUCCESS; } public void setRequest(Map<String, Object> request) { this.request=request; }
然后
jsp
<table border="1" bordercolor="red" bgcolor="blue"> <tr><th>ID</th><th>DEP</th></tr> <c:forEach var="sta" items="${list}"> <tr> <td>${sta.id}</td> <td>${sta.name}</td> </tr> </c:forEach> </table>
一直打印出出来id和name,后来经人提醒“c标签库引了么”,才发现要引入标签库
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
但是报错
"items" does not support runtime exception
看了网上的帖子后,把他改成
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
或者
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
这样就可以了