【发布时间】:2011-12-03 00:01:04
【问题描述】:
我在我的应用程序中使用 Spring 2.5。在视图中,我有主 jsp,其中包含了另一个 jsp。我在主 jsp 中使用 c:set 标记声明了一个变量,我无法在 jsp 中访问该变量。下面是代码 main.jsp
<c:set var="hPediquestStudy"><spring:message code="study.hpediquest.mapping" /></c:set>
<c:set var="currentStudy" value='<%=(String)session.getAttribute("currentStudy")%>'/>
<html>
<head>
</head>
<body>
<c:if test="${currentStudy eq hPediquestStudy}">
Variables are equal
</c:if>
<c:if test="${currentStudy ne hPediquestStudy}">
Variables are not equal
</c:if>
<jsp:include page="/WEB-INF/jsp/included.jsp"></jsp:include>
</body
</html>
included.jsp
<c:if test="${currentStudy eq hPediquestStudy}">
hPediquestStudy Variable is accessible
</c:if>
<br/>currentStudy : ${currentStudy}
<br/>hPediquestStudy : ${hPediquestStudy}
我得到输出
变量相等
currentStudy : hPediquest
hPediquestStudy:
- 为什么在主 jsp 上两个值相等,而在包含 jsp 中我看不到它的值?
- 为什么 currentStudy 在包含的 jsp 中显示它的值?
- 是否有任何解决方案可以帮助我访问在父 jsp 中设置的变量,并且可以在包含的 jsp 中访问?
如果我像在主 jsp 中一样在包含的 jsp 中设置该变量,我可以看到 hPediquestStudy 的值。但是我不想每次包含jsp时都设置它。请帮忙
【问题讨论】: