Pregunta

My question is really simple and I know there is an obvious answer to this. I am using jsp files and what I want to happen is when I click on page one only a link to page two will show up and vice versa when I click on page 2. But when I am on either page a link to both pages still shows up. Any idea on how to change this? Thank-you.

Menu

    <ul id="Menu">

            <li<c:if test="${param.active == 'Pageone'}"> class="active"</c:if>>
                <a href="Pageone.jsp">Pageone</a>
            </li>



            <li<c:if test="${param.active == 'Pagetwo'}"> class="active"</c:if>>
                <a href="Pagetwo.jsp">Pagetwo</a>
            </li>


    </ul>

Pageone

    <jsp:include page="menu.jsp">
        <jsp:param name="active" value="Pageone" />
    </jsp:include>

Pagetwo

            <jsp:include page="menu.jsp">
                <jsp:param name="active" value="Pagetwo" />
            </jsp:include>
¿Fue útil?

Solución

I don't know what are you doing in active CSS style?

Simply do not add the link if condition is not satisfied.

Show link for Pageone.jsp if you are on Pagetwo.jsp and vice-verse. Please confirm.

<ul id="Menu">

   <c:if test="${param.active eq 'Pagetwo'}">
        <li class="active">
            <a href="Pageone.jsp">Pageone</a>
        </li>
   </c:if>


   <c:if test="${param.active eq 'Pageone'}">
        <li class="active">
            <a href="Pagetwo.jsp">Pagetwo</a>
        </li>
   </c:if>

</ul>

For more samples have a look at Is there an easy way to compare two strings in JSP?

Otros consejos

You may simply append the parameter to get single link at a time tested and works for me:

<c:set var="text" value="Pageone"/>
<c:if test="${param.active eq text}">
  <c:set var="text" value="Pagetwo"/>
</c:if>

<ul id="Menu">
   <li class="active">
       <a href="${text}.jsp">${text}</a>
   </li>
</ul>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top