<%-- item.jsp Alan Pinder - April 10th 2005 This page is an 'include' page. It is never shown by itself, rather it is always 'included' by using the <%-- Standard page declarations --%> <%@ page import="apz.db.*" %> <%@ page session="true" %> <%@ page errorPage="error.jsp" %> <%! // Static declarations - these are available throughout the entire page // BUT can't use any instance objects private static String getAvailability(int pNumInStock) { if (pNumInStock == 0) return "Sold out!"; if (pNumInStock < 5) return "Limited"; return "Available"; } private static String getScore(int pScore) { String tempString = ""; for(int i=0; i"; for(int i=0; i<(5 - pScore); i++) tempString += "*"; return (tempString += ""); } %> <% DbItem currentItem = null; // Reference to current item DbItem.Review[] itemReviews = null; // Items reviews // Good old parameter validation once more try { // Check itemID is present, long, and valid String tempString = request.getParameter("itemID"); if (tempString == null) throw new DbNullPointerException("itemID"); long itemID = Long.parseLong(tempString); if (DB.doesItemExist(itemID) == false) throw new DbItemNotFoundException(itemID); // Success currentItem = DB.getItem(itemID); itemReviews = currentItem.getReviews(); } catch(NumberFormatException e) { throw new DbValidationException("Item ID not numeric"); } %> <%= currentItem.getName() %>
<%= currentItem.getName() %>
Item Description
<%= currentItem.getImagePath() %> Price: £<%= currentItem.getPrice() %>
Num In Stock: <%= currentItem.getNumInStock() %>
Availability: <%= getAvailability(currentItem.getNumInStock()) %>
Average Score: <%= ((double)((int)(currentItem.getAverageScore() * 100)) / 100) %>
Based on <%= itemReviews.length %> reviews
<%= currentItem.getDescription() %>
<% for(int i=0; i\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); } %>
Reviewer Rating
Review
" + itemReviews[i].getReviewer() + "" + getScore(itemReviews[i].getScore()) + "" + itemReviews[i].getReview() + "