I'm stuck on trying to get and print the table of data. I think I set up the request correctly, in servlet but when I try to get the list of book in test.jsp, it says the server encountered an unexpected condition that prevented it from fulfilling the request. Is that where they should go? I feel like I'm missing something or they completely wrong, but I can't figure out what. Thanks for any help.
in the servletTest
public class TestServlet extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String userPath="/test";
String url = "/WEB-INF/jsp"+userPath+".jsp";
String categoryName = request.getParameter("category");
request.setAttribute("selectedCategoryName", categoryName);
CategoryDao categoryDao =
ApplicationContext.INSTANCE.getCategoryDao();
BookDao bookDao = ApplicationContext.INSTANCE.getBookDao();
request.setAttribute("bookList",bookDao);
request.getRequestDispatcher(url).forward(request,response);
}
In the test.jsp
<body>
<ul>
<li><a href="test?category=architecture">architecture</a></li>
<li><a href="test?category=fine art">fine art</a></li>
<li><a href="test?category=fashion">fashion</a></li>
<li><a href="test?category=photography">photography</a></li>
<li><a href="test?category=graphic">graphic</a></li>
</ul>
<c:set var="categoryName">${selectedCategoryName}</c:set>
<h1><span style="size: 14px">${categoryName}</span> </h1>
<table border="1">
<tr>
<th>book_id</th>
<th>title</th>
<th>author</th>
<th>price</th>
<th>is_public</th>
<th>category_id</th>
</tr>
<c:forEach var="book" items="${bookList}">
<tr>
<td>${book.bookId}</td>
<td>${book.title}</td>
<td>${book.author}</td>
<td>${book.price}</td>
<td>${book.is_public}</td>
<td>${book.category_id}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
Book class
public class Book {
private long bookId;
private String title;
private String author;
private int price;
private boolean isPublic;
private Long categoryId;
public Book(long bookId, String title, String author, int price,
boolean isPublic, long categoryId) {
this.bookId = bookId;
this.title = title;
this.author = author;
this.price = price;
this.isPublic = isPublic;
this.categoryId = categoryId;
}
public long getBookId() {
return bookId;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getPrice() {
return price;
}
public boolean getIsPublic() {
return isPublic;
}
@Override
public String toString() {
return "Book{" +
"bookId=" + bookId +
", title='" + title + '\'' +
", author='" + author + '\'' +
", price=" + price +
", isPublic=" + isPublic +
", categoryId=" + categoryId +
'}';
}
}