我不认为你真的想要这里的标签文件。对于您想要完成的任务来说,这太过分了,而且太令人困惑了。您需要花时间理解“范围”。我会:而不是标记文件:
1)通过更改此行将您的属性更改为“请求”范围而不是默认的“页面”范围:
<c:forEach items="${attributeDTOList}" var="attribute" varStatus="status">
to this
<c:forEach items="${attributeDTOList}" var="attribute" varStatus="status">
<c:set var="attribute" value="${attribute}" scope="request"/>
这将使“attribute”成为“requestScope”变量,可以在 c:import 的其他 JSP 文件中使用。 (注意:forEach 不支持作用域属性,因此请使用 c:set 在每次迭代中对其进行作用域。)
2)将原来的jsp:include改为c:import。因此将其更改为:
<jsp:include page="attributeSubFeatureRemove.jsp" >
<jsp:param name="attribute" value="${attribute}" />
</jsp:include>
to this
<c:import url="attributeSubFeatureRemove.jsp"/>
请注意,我们不会显式尝试将该属性作为参数传递,因为我们已经将其提供给“requestScope”中的所有 c:imported 页面。
3) 修改您的 c:imported JSP,通过更改以下内容来使用 requestScope 引用该属性:
<c:set value="${param.attribute}" var="attribute" />
<c:forEach items="${attribute.subFeatures}" var="subAttribute">
to this
<c:forEach items="${requestScope.attribute.subFeatures}" var="subAttribute">
在这里,我们不再需要 c:set,因为您已经拥有可用的属性。我们只需要确保在 requestScope 中查找该变量,而不是在默认 pageScope 中或作为参数(因为我们不再将其作为参数传递)。
这种技术对你来说会更容易管理。