在我的Jsp页面中,出现错误:
在的Bean中找不到有关属性“ productList”的任何信息
键入“ Smithd81.InventoryManager”
InventoryManager类具有getProductList()方法,该方法返回我需要访问的产品对象列表。
在我的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;
}
}
最佳答案
将软件包名称重构为小写。另一种情况是您尝试在对象上调用静态方法(您的bean最终是对象)。因此,方法getProductList()
应该是非静态的。