我遇到了这样的问题。我写了这样的jstl代码:
<c:forEach var="package" items="${hotel.packages}">
<c:forEach var="product_item" items="${package.items}">
//some inputs and so on
</c:forEach>
</c:forEach>
我的模型类看起来像这样:
酒店课程
private java.util.Set<com.acmecorp.acmeproject.model.catalog.hotel.HotelPackage> packages;
public java.util.Set<com.acmecorp.acmeproject.model.catalog.hotel.HotelPackage> getPackages() { /* compiled code */ }
public void setPackages(java.util.Set<com.acmecorp.acmeproject.model.catalog.hotel.HotelPackage> packages) { /* compiled code */ }
HotelPackage
public java.util.Set<com.acmecorp.acmeproject.model.catalog.hotel.HotelPackageItem> getItems() { /* compiled code */ }
public void setItems(java.util.Set<com.acmecorp.acmeproject.model.catalog.hotel.HotelPackageItem> items) { /* compiled code */ }
private java.util.Set<com.acmecorp.acmeproject.model.catalog.hotel.HotelPackageItem> items;
我正在发布此消息
org.apache.jasper.JasperException: /WEB-INF/view/controls/hotelPackages/hotelPackagesView.jsp (line: 165, column: 24) "${package.items}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${package.items}]
试图打开我的jsp。
第164行是这一行<c:forEach var="product_item" items="${package.items}">
那么,可能有人知道这是什么问题?
答案 0 :(得分:1)
我认为这是因为'package'是一个保留的Java关键字。尝试将其重命名为其他任何内容。
答案 1 :(得分:0)
这是你的答案!
public class Hotel {
public java.util.HashSet<HotelPackage> packages;
public java.util.HashSet<HotelPackage> getPackages() {
return packages;
}
public void setPackages(java.util.HashSet<HotelPackage> packages) {
this.packages = packages;
}
}
public class HotelPackage {
public java.util.HashSet<String> items;
public java.util.HashSet<String> getItems() {
return items;
}
public void setItems(java.util.HashSet<String> items) {
this.items = items;
}
}
<%
HashSet items = new HashSet();
Hotel hotel = new Hotel();
HashSet hotelPackSet = new HashSet();
HotelPackage hp1 = new HotelPackage();
HashSet items1 = new HashSet();
items1.add("Buffet");
items1.add("Luxury Rooms");
hotelPackSet.add(hp1);
HotelPackage hp2 = new HotelPackage();
HashSet items2 = new HashSet();
hp2.setItems(items2);
items2.add("Swimming Pool");
items2.add("Common Rooms");
hotelPackSet.add(hp1);
hotelPackSet.add(hp2);
hotel.setPackages(hotelPackSet);
%>
<c:set property="hotel" scope="page" value="<%= hotel%>" var="hotel"/>
<c:forEach var="pack" items="${hotel.packages}">
<c:set property="packItem" scope="page" value="${pack.items}" var="pack"/>
<c:forEach var="product_item" items="${pack}">
${product_item}
</c:forEach>
</c:forEach>
因此,如果没有在set变量中设置var,你就会犯一个大错误。欢呼:)