weixin_44934855
EGFERH
2019-07-19 13:28

request的getAttribute方法无法解析list中的对象

  • java-ee

List list = new ArrayList();
while(rs.next()){
Book book = new Book();
book.setId(rs.getInt("id"));
book.setName(rs.getString("name"));
book.setPrice(rs.getDouble("price"));
book.setCount(rs.getInt("count"));
book.setAuthor(rs.getString("author"));
list.add(book);
}
request.setAttribute("list", list);

        request.getRequestDispatcher("book_list.jsp").forward(request, response);

<%
List list = request.getAttribute("list");
if (list == null || list.size() out.print("没有数据");
}else{
for(Book book:list){
%>

<%=book.getId()%>
<%=book.getName()%>
<%=book.getPrice()%>
<%=book.getCount()%>
<%=book.getAuthor()%>

<%
}
}
%>

名称为FindServlet的Servlet的对象将Book集合放置到request中转发到book_list.jsp中,在book_list.jsp中获取Book集合时报错。提示Book cannot be resolved to a type。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答