Sunday, March 1, 2015

Do I have to "deserialize" an ArrayList to retract the values?








I have a class that creates BOOK objects, with properties such as title, author, year ....








I am using NetBeans and was able to successfully code a method to "checkout" these books from the library in which case it is written to a MySQL database file.








There is another method which selects all the entries in the library database so you can view checked out books. This is done through a prepareStatement query and a ResultSet. This appears to be operating fine - I tested with various System.out.println() statements. The method returns an ArrayList of <Book> objects.








Back in my controller I want to send this list to a JSP page to print out on the web. Here is where it tends to get sticky. Again, I created arraylist and the entries are there (I can tell from the .size() attribute), but when I read the data out it doesn't make sense (I assume because the Book class implements serializable).








The questions - Do I have to deserialize this before sending it to my JSP page? How do you deserialize an array list?








Thanks in advance. Here is a bit of what I've done to test:












Java Code:











// ----------------- LIST OF CHECKED OUT BOOKS -----------------
private String manage(HttpServletRequest request,
HttpServletResponse response) {
//TODO: Implement code to display list of checked out books here.

ArrayList<Book> list = CheckoutDb.manage();

for (Book b : list) { // ----------------------------- TROUBLESHOOTING
b.getBookTitle();
b.getFirstName();
b.getLastName();
}
System.out.println("--------------------- " + checkedOutList.size()); // ------ TROUBLESHOOTING
request.setAttribute("checkedOutList", CheckoutDb.manage());

return "/checkedOutList.jsp";
}
















No comments:

Post a Comment