问候,这是问题所在。我有一个网页叫做entList.jsp,与收集工作:可以jsp:param存储一个集合吗?
<c:forEach var = "pack" items = "${packingList}">
<!--Here goes something with outputting the pack instance in a required format-->
</c:forEach>
一切的伟大工程,并PACKINGLIST,作为调用这个页面的操作处理程序请求的属性被传递的参数。其实packingList是集合<GenericBean>。
事实证明,这个页面(它存储的片段)实际上非常有用,并且可以在许多具有不同集合的地方使用。于是,我就包括这个页面是这样的(在另一页):
<jsp:include page="entList.jsp">
<!-- Pass the required collection as a parameter-->
<jsp:param name = "packingList" value = "${traffic.packingList}"/>
</jsp:include>
然而,现在这个片段不看参数PACKINGLIST。我试图改写这样的片段(因为现在它的一个参数):
<c:forEach var = "pack" items = "${param.packingList}">
<!--Here goes something with outputting the pack instance in a required format-->
</c:forEach>
但现在它会产生一个例外,因为它把PACKINGLIST作为一个字符串,而不是一个集合。所以现在的解决方案是这样的 - 设置所需的集合作为在动作处理程序代码的属性:
// This is the original instance set by the action
request.setAttribute("traffic", traffic);
// And this is the additional one, to be used by entList.jsp
request.setAttribute("packingList", traffic.getPackingList());
所以,问题是 - 可以JSP:PARAM标签接收集合,因为它的价值呢?我阅读了JSP标签的文档,目前还不清楚 - 看起来你可以通过这种方式传递字符串参数(或者可以转换为字符串的东西),但没有复杂的对象。