jstl 中嵌套 c:foreach

发布于 2024-10-20 09:30:31 字数 2937 浏览 1 评论 0原文

我正在使用 JSTL 从一个 bean 检索值。它里面包含一个豆子,而这个豆子又包含另一个豆子。 示例 bean 如下所示

Page.java

public class Page {
    private List<Column> columnList;
    private String emailAddr;
    public List<Column> getColumnList() {
        return columnList;
    }
    public void setColumnList(List<Column> columnList) {
        this.columnList = columnList;
    }
    public String getEmailAddr() {
        return emailAddr;
    }
    public void setEmailAddr(String emailAddr) {
        this.emailAddr = emailAddr;
    }
}

Column.java

public class Column {
    private List<MyBean> columnList;
    public String getDispCatg(){
        return dispCatg;
    }

    public void setDispCatg(String dispCatg) {
        this.dispCatg = dispCatg;
    }

    private String dispCatg;
    public List<MyBean> getColumnList() {
        return columnList;
    }

    public void setColumnList(List<MyBean> columnList) {
        this.columnList = columnList;
    }

}

MyBean.java

public class MyBean {
    private static int i=0;
    private String value;
    public String getValue() {
        return String.valueOf(++i);
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String getDescription() {
        return "FirstCheckBox"+i;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    private String description;
    public MyBean() {
        // TODO Auto-generated constructor stub
    }

}

我需要访问 MyBean 值。我怎样才能找回? 我尝试了以下方法...但是 Jsp 未编译。

<c:forEach items="${dataBean.columnList}" var="column1" varStatus="rowStatus">
        <c:forEach items="${column1}" var="column2" varStatus="rowCount">
            <c:forEach items="${column2}" var="bean" varStatus="rowCount">
                <div>hello 1..2..3</div>
            </c:forEach>
        </c:forEach>
    </c:forEach>

完整的异常描述 java.lang.NoSuchFieldError:deferredExpression org.apache.taglibs.standard.tag.common.core.ForEachSupport.release(ForEachSupport.java:178) org.apache.jasper.runtime.TagHandlerPool.release(TagHandlerPool.java:166) org.apache.jsp.BeanLoad_jsp._jspDestroy(BeanLoad_jsp.java:39) org.apache.jasper.runtime.HttpJspBase.destroy(HttpJspBase.java:61) org.apache.jasper.servlet.JspServletWrapper.destroy(JspServletWrapper.java:428) org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:139) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

I am working on JSTL to retrieve values from one bean. It contains one bean inside and this bean contains another bean.
sample beans look like this

Page.java

public class Page {
    private List<Column> columnList;
    private String emailAddr;
    public List<Column> getColumnList() {
        return columnList;
    }
    public void setColumnList(List<Column> columnList) {
        this.columnList = columnList;
    }
    public String getEmailAddr() {
        return emailAddr;
    }
    public void setEmailAddr(String emailAddr) {
        this.emailAddr = emailAddr;
    }
}

Column.java

public class Column {
    private List<MyBean> columnList;
    public String getDispCatg(){
        return dispCatg;
    }

    public void setDispCatg(String dispCatg) {
        this.dispCatg = dispCatg;
    }

    private String dispCatg;
    public List<MyBean> getColumnList() {
        return columnList;
    }

    public void setColumnList(List<MyBean> columnList) {
        this.columnList = columnList;
    }

}

MyBean.java

public class MyBean {
    private static int i=0;
    private String value;
    public String getValue() {
        return String.valueOf(++i);
    }
    public void setValue(String value) {
        this.value = value;
    }
    public String getDescription() {
        return "FirstCheckBox"+i;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    private String description;
    public MyBean() {
        // TODO Auto-generated constructor stub
    }

}

And I need to access MyBean values. How can i retrieve?
i tried below way...But Jsp is not compiled.

<c:forEach items="${dataBean.columnList}" var="column1" varStatus="rowStatus">
        <c:forEach items="${column1}" var="column2" varStatus="rowCount">
            <c:forEach items="${column2}" var="bean" varStatus="rowCount">
                <div>hello 1..2..3</div>
            </c:forEach>
        </c:forEach>
    </c:forEach>

full exception description
java.lang.NoSuchFieldError: deferredExpression
org.apache.taglibs.standard.tag.common.core.ForEachSupport.release(ForEachSupport.java:178)
org.apache.jasper.runtime.TagHandlerPool.release(TagHandlerPool.java:166)
org.apache.jsp.BeanLoad_jsp._jspDestroy(BeanLoad_jsp.java:39)
org.apache.jasper.runtime.HttpJspBase.destroy(HttpJspBase.java:61)
org.apache.jasper.servlet.JspServletWrapper.destroy(JspServletWrapper.java:428)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:139)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴骨ら 2024-10-27 09:30:31

如果 dataBean 是一个 Page 对象,那么我认为按如下方式修改 JSTL 将使其编译。我不认为你的第二个 forEach 调用了返回 Collection 对象进行迭代的方法。我相信第三个嵌套的 forEach 可以被删除,因为到第二个嵌套时,您将使用 MyBean 对象。

   <c:forEach items="${dataBean.columnList}" var="column" varStatus="rowStatus">
            <c:forEach items="${column.columnList}" var="mybean" varStatus="rowCount">
                <div>hello 1..2..3..<c:out value="${mybean.description}"/></div>
            </c:forEach>
    </c:forEach>

If dataBean is a Page object then I think modifying your JSTL as follows will make it compile. I don't think your second forEach was calling a method that returned a Collection object to iterate over. I believe the third nested forEach can be removed because by the second one you will be working with MyBean objects.

   <c:forEach items="${dataBean.columnList}" var="column" varStatus="rowStatus">
            <c:forEach items="${column.columnList}" var="mybean" varStatus="rowCount">
                <div>hello 1..2..3..<c:out value="${mybean.description}"/></div>
            </c:forEach>
    </c:forEach>
不忘初心 2024-10-27 09:30:31

尝试将第二行从 替换

<c:forEach items="${column1}" var="column2" varStatus="rowCount">

<c:forEach items="${column1.columnList}" var="column2" varStatus="rowCount">

Try to replace second row from

<c:forEach items="${column1}" var="column2" varStatus="rowCount">

to

<c:forEach items="${column1.columnList}" var="column2" varStatus="rowCount">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文