在我的 Jsp 页面中,我收到错误:
Cannot find any information on property 'productList' in a bean of type '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;
}
}
最佳答案
将您的包名称重构为小写。另一种情况是您试图调用对象上的静态方法(您的 bean 最终是对象)。因此方法 getProductList()
应该是非静态的。
关于java - 在 Java JSP 页面中找不到有关属性的任何信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35831471/