【问题标题】:Cannot find any information on property in Java JSP page在 Java JSP 页面中找不到任何有关属性的信息
【发布时间】:2016-03-06 19:28:47
【问题描述】:

在我的 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;
        }
    }

【问题讨论】:

    标签: java jsp javabeans


    【解决方案1】:

    将你的包名重构为小写。另一种情况是您试图在对象上调用静态方法(您的 bean 最终是对象)。所以方法getProductList() 应该是非静态的。

    【讨论】:

    • 当我这样做时,它说包名 smithd81 已经存在;我在哪里检查这个?
    • 没关系,我找到了重命名它的解决方法。但是,我仍然收到原始错误
    • 我刚刚看到您正在尝试在对象上调用静态方法(您的 bean 最终是对象)。所以方法getProductList() 应该是非静态的。
    • 请将您的最后一条评论作为完整回复发表,以便我接受。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2011-09-05
    • 2012-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多