在我的Jsp页面中,我收到错误:
找不到有关物业及产品清单的任何资料。在一个豆子里 键入' Smithd81.InventoryManager'
InventoryManager类有一个getProductList()方法,它返回我需要访问的Product对象列表。
在我的JSP中:
<jsp:useBean id = "productManager" scope = "page" class = "Smithd81.InventoryManager" />
<jsp:getProperty name = "productManager" property = "productList" />
我认为我在getProperty属性名称上有这个正确 - 以小写字母开头,诸如此类,这是此错误的典型陷阱,但我确实拼写正确。
我似乎得到了错误:
<c:forEach var="p" items="${productManager.productList}">
<div>
<form action="inventory" method="POST">
<label>
<span>UPC</span>
<input type="text" name="upc" value="${p.getUpc()}" readonly="readonly"/>
</label>
<label>
<span>Short Details</span>
<input type="text" name="shortDetails" value="${p.getShortDetails()}" />
</label>
<label>
<span>Long Details</span>
<input type="text" name="longDetails" value="${p.getLongDetails()}" />
</label>
<label>
<span>Price</span>
<input type="text" name="price" value="${p.getPrice()}" />
</label>
<label>
<span>Stock</span>
<input type="text" name="stock" value="${p.getStock()}" />
</label>
<input type="submit" name="button" value="Edit" />
<input type="submit" name="button" value="Delete" />
</form>
</div>
</c:forEach>
为了澄清,在InventoryManager类中,方法签名为:
public static List getProductList() throws IOException, ClassNotFoundException {
try {
List<Product> productsList = new ArrayList<>(); //empty product list
Collection<Product> productsFromFile = CollectionFileStorageUtility.load(Product.class);//loads collection from file
productsList.addAll(productsFromFile);// adds all current products from file to the productList List.
return productsList;
} catch (IOException e) {
System.out.println("IOException: error accessing data file.");
return null;
} catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException: error accessing class.");
return null;
}
}
答案 0 :(得分:1)
将您的包名重构为小写。另一种情况是你试图在对象上调用静态方法(你的bean最终是对象)。所以方法getProductList()
应该是非静态的。