gpt4 book ai didi

java - 使用 c :foreach, 迭代包含 Bean 对象的 ArrayList 不起作用

转载 作者:行者123 更新时间:2023-12-01 22:46:00 24 4
gpt4 key购买 nike

我正在 JSP 中迭代 ArrayList,其中包含 Bean 的对象。我想使用 getter() 从该对象中提取信息。ProductID 是我感兴趣的属性之一。我使用 JSTL 来实现此目的。代码如下:

<c:forEach items="repo" var="element">
<jsp:useBean id="element" scope="page" class="com.ResponseBean"/>
Product:<jsp:getProperty property="ProductID" name="element"/>
</c:forEach>

其中repo是ArrayList,其中包含ResponseBean的对象。

List<ResponseBean> repo=new ArrayList<ResponseBean>(10);

ResponseBean的代码如下:

public class ResponseBean implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String ProductID;
public String getProductID() {
return ProductID;
}
public void setProductID(String productID) {
ProductID = productID;
}

但是我遇到了以下异常

HTTP Status 500 - Cannot find any information on property 'ProductID' in a bean of type 'com.ResponseBean'

type Exception report

message Cannot find any information on property 'ProductID' in a bean of type 'com.ResponseBean'

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Cannot find any information on property 'ProductID' in a bean of type 'com.ResponseBean'
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:824)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1081)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1125)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2427)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1784)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2427)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2433)
org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Generator.generate(Generator.java:3517)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:250)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.52 logs.
Apache Tomcat/7.0.52

哪里出了问题?

最佳答案

你不需要这样做,你可以简单地使用EL

<c:forEach items="repo" var="element">
Product: ${element.productID}
</c:forEach>

关于java - 使用 c :foreach, 迭代包含 Bean 对象的 ArrayList 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357980/

24 4 0