java - 在 Java JSP 页面中找不到有关属性的任何信息

标签 java jsp javabeans

在我的 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/

相关文章:

java - 多个提交按钮安全风险

java - 想使用 Java 制作网站,我应该实现 struts 吗?

java - 在 IntelliJ 中创建 Android 项目时如何设置我的 Java SDK?

java - Junit:在多个测试类中使用相同的测试对象

security - 利用和纠正路径遍历漏洞

java - 使用Spring框架的构造函数依赖注入(inject),无法保留值

没有 xml bean 定义的 Spring 组件检测

java - 最后在异常处理

java - 在Fragment事务中杀死AsyncTask

java - DAO 和 Spring Beans 有什么区别?