jstl 中嵌套 c:foreach
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 dataBean 是一个 Page 对象,那么我认为按如下方式修改 JSTL 将使其编译。我不认为你的第二个 forEach 调用了返回 Collection 对象进行迭代的方法。我相信第三个嵌套的 forEach 可以被删除,因为到第二个嵌套时,您将使用 MyBean 对象。
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.
尝试将第二行从 替换
为
Try to replace second row from
to