servlet的代码:
/查找图书的集合
public String findAll(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setAttribute("bookList", bookService.findAll());//将bookList对象保存到request域中
return "f:/jsps/book/list.jsp";//转发到list.jsp页面上
}
//按条件查询
public String findByCategory(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String cid=req.getParameter("cid");//拿到传输过来的id
req.setAttribute("bookList", bookService.findByCategory(cid));//通过条件查询到书,并封装成bookList保存到request域中
return "f:/jsps/book/list.jsp";//转发到list.jsp页面上
}
//按单本书查询
public String load(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String bid=req.getParameter("bid");//拿到传输过来的id
req.setAttribute("book", bookService.load(bid));//通过条件查询到书,并封装成book保存到request域中
return "f:/jsps/book/desc.jsp";//转发到desc.jsp页面上
}
jsp的一些代码:
<c:forEach items="${bookList }" var="book">
<div class="icon">
<a href="<c:url value='/BookServlet?method=load&bid=${book.bid}'/>"><img src="<c:url value='/${book.image }'/>" border="0"/></a>
<br/>
<a href="<c:url value='/BookServlet?method=load&bid=${book.bid}'/>">${book.bname}</a>
</div>
</c:forEach>