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?
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
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
or that JSTL isn't installed at all. Download and install it as per the instructions in our JSTL wiki page.
精彩评论