jsp选择语句
我有一个 header.jsp,我想将其包含在多个页面中。标题页中有三个链接。我使用 css 向用户指示他们在任何给定点所在的页面。下面是 header.html 的代码:
<ul>
<%-- Check for the activeState parameter to decide which css to use --%>
<c:choose>
<c:when test='${requestScope.activeState == "home"}'>
<li><a href="index.jsp" class="active"><span>Home</span></a></li>
</c:when>
<c:otherwise>
<li><a href="index.jsp"><span>Home</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='${requestScope.activeState == "about"}'>
<li><a href="about.jsp" class="active"><span>About Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="about.jsp"><span>About Us</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='${requestScope.activeState == "contact"}'>
<li><a href="contact.jsp" class="active"><span>Contact Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="contact.jsp"><span>Contact Us</span></a></li>
</c:otherwise>
</c:choose>
</ul>
这是 index.jsp 文件调用的内容:
<jsp:include page="header.jsp">
<jsp:param value="home" name="activeState"/>
</jsp:include>
这不起作用。 index.html 页面中显示了六个链接。三个带 css,三个不带 css。以下是 index.html 页面的源代码:
<c:choose>
<c:when test='false'>
<li><a href="index.jsp" class="active"><span>Home</span></a></li>
</c:when>
<c:otherwise>
<li><a href="index.jsp"><span>Home</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='false'>
<li><a href="about.jsp" class="active"><span>About Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="about.jsp"><span>About Us</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='false'>
<li><a href="contact.jsp" class="active"><span>Contact Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="contact.jsp"><span>Contact Us</span></a></li>
</c:otherwise>
</c:choose>
我还尝试使用 param.activeState
而不是 requestScope.activeState
来获取 activeState 参数。行为没有改变。有人可以解释一下发生了什么事吗?
I have a header.jsp that I want to include in multiple pages. The header page has three links in it. I am using css to indicate to the user which page they are on at any given point. Here is the code for header.html:
<ul>
<%-- Check for the activeState parameter to decide which css to use --%>
<c:choose>
<c:when test='${requestScope.activeState == "home"}'>
<li><a href="index.jsp" class="active"><span>Home</span></a></li>
</c:when>
<c:otherwise>
<li><a href="index.jsp"><span>Home</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='${requestScope.activeState == "about"}'>
<li><a href="about.jsp" class="active"><span>About Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="about.jsp"><span>About Us</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='${requestScope.activeState == "contact"}'>
<li><a href="contact.jsp" class="active"><span>Contact Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="contact.jsp"><span>Contact Us</span></a></li>
</c:otherwise>
</c:choose>
</ul>
This is what the index.jsp file calls:
<jsp:include page="header.jsp">
<jsp:param value="home" name="activeState"/>
</jsp:include>
This does not work. Six links are showed in the index.html page. Three with css and three without css. Here is what the source looks like for the index.html page:
<c:choose>
<c:when test='false'>
<li><a href="index.jsp" class="active"><span>Home</span></a></li>
</c:when>
<c:otherwise>
<li><a href="index.jsp"><span>Home</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='false'>
<li><a href="about.jsp" class="active"><span>About Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="about.jsp"><span>About Us</span></a></li>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test='false'>
<li><a href="contact.jsp" class="active"><span>Contact Us</span></a></li>
</c:when>
<c:otherwise>
<li><a href="contact.jsp"><span>Contact Us</span></a></li>
</c:otherwise>
</c:choose>
I also tried to get the activeState parameter using the param.activeState
instead of requestScope.activeState
. No change in behavior. Can somebody explain what is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您看到 HTML 源代码中未解析 JSTL 标记,则意味着 JSTL 标记库未在 JSP 顶部声明,如下所示
,或者根本未安装 JSTL。按照我们的 JSTL wiki 页面 中的说明下载并安装它。
If you see the JSTL tags unparsed in the HTML source, then it means that either the JSTL taglib isn't been declared in top of JSP as follows
or that JSTL isn't installed at all. Download and install it as per the instructions in our JSTL wiki page.