jsp选择语句

发布于 2024-10-12 19:15:14 字数 2923 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-10-19 19:15:14

如果您看到 HTML 源代码中未解析 JSTL 标记,则意味着 JSTL 标记库未在 JSP 顶部声明,如下所示

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

,或者根本未安装 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

<%@ 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文