关于jstl报错
index.jsp页面:
<c:forEach items="${listtype}" var="listtype" varStatus="len">
<a href="#">${listtype.typename} | </a>
</c:forEach>
servlet:
goodsDao gdp = new goodsDaoImpl();
List<typename> listtype = gdp.selectType();
Goods listpp = gdp.selectPP();
req.getSession().setAttribute("listtype", listtype);
req.getSession().setAttribute("listpp", listpp);
req.getRequestDispatcher("index.jsp").forward(req, resp);
实体类:
public class typename {
private String name;
public void setTypename(String name){
this.name = name;
}
public String getTypename(){
return name;
}
}
select方法:
public List<typename> selectType() {
List<typename> listtype = new ArrayList<typename>();
typename type = null;
String sql = "select t.typename from fsg_goods g,fsg_goodstype t "+
" where t.id = g.typeid group by t.typename";
try{
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
type = new typename();
type.setTypename(rs.getString(1));
listtype.add(type);
}
}catch(Exception ex){
ex.printStackTrace();
}
//super.closeAll(conn, ps, rs);
return listtype;
}
报错:
严重:
Servlet.service() for servlet jsp threw exceptionjavax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>
这是为什么呢,我百度了,百度上都说这个传进来的值要是集合才行,不然就报此错误,问题是我的一直都是集合呀,集合里面的值是一个对象呀,可为什么还是报了一样的错呢,请各位指教,急!!!!
------解决方案--------------------
如果你把jstl的包引入进去了,那么就应该是你传的值有问题,你可以先在后台将listtype打印出来看看你传的值到底是什么。