Java 多重<;c:在<;c:选择+;饼干

Java 多重<;c:在<;c:选择+;饼干,java,list,jsp,cookies,jstl,Java,List,Jsp,Cookies,Jstl,您好,我正在尝试创建一个有序列表,可以根据cookie的值显示移动到各个页面的选项。cookie已正确设置。它的价值正在被获得。。但是有一些错误我不能很准确地指出 <c:forEach items= "${cookie}" var="currentCookie"> <c:if test="${currentCookie.key eq 'user_type' }"> <c:set var="user_type" value = "${curr

您好,我正在尝试创建一个有序列表,可以根据cookie的值显示移动到各个页面的选项。cookie已正确设置。它的价值正在被获得。。但是有一些错误我不能很准确地指出

     <c:forEach items= "${cookie}" var="currentCookie">
    <c:if test="${currentCookie.key eq 'user_type' }">
    <c:set var="user_type" value = "${currentCookie.value.value }"/>
    </c:if>
     </c:forEach>



     <c:choose>
<c:when test="${not empty user_type}">
    <li><a class="" href="#">SELECT</a>
    <ul>
    <c:when test="${user_type='T'}"><li><a href="/myproject/f/auction_history/">My Account</a></li></c:when>
    <c:when test="${user_type='P'}"><li><a href="/myproject/f/auction_history/">My Account</a></li></c:when>
    <c:when test="${user_type='D'}"><li><a href="/myproject/f/menubarCreateAuction/">Create Auction</a></li></c:when>
    <c:when test="${user_type='F'}"><li><a href="/myproject/f/menubarDfoManagement/">DFO Management</a></li></c:when>
    <c:when test="${user_type='S'}"><li><a href="/myproject/f/menubaruserManagement/">User Management</a></li></c:when>
    </ul>
    </li>
</c:when>
<c:otherwise>
    <li><a class="" href="#">SELECT</a>
    <ul>
        <li><a href="/myproject/f/menubarCreateAuction/">Create Auction</a></li>
        <li><a href="/myproject/f/menubarDfoManagement/">DFO Management</a></li>
        <li><a href="/myproject/f/menubaruserManagement/">User Management</a></li>
    </ul>
    </li>

</c:otherwise>

  • foreach选择各种Cookie并获取用户类型的Cookie并获取值

    在c中,选择cookie的值与生成有序列表的预定值进行比较 如果未选择任何值,则列表中只应显示3项


    请提供帮助。

    以下代码似乎没有问题,将检索上次出现的“用户类型”cookie的值

    <c:forEach items= "${cookie}" var="currentCookie">
        <c:if test="${currentCookie.key eq 'user_type' }">
            <c:set var="user_type" value = "${currentCookie.value.value }"/>
        </c:if>
    </c:forEach>
    

    在上述代码中,进行了以下更改:

    • 添加了一个结束语
      更正了
    • 标签的使用,因为这是不正确的
    • 更正了
      test
      语句以使用
      eq
    • 为条件选项添加了嵌套的
    • 添加了一个注释来考虑代码< UsRyType < /代码>的状态不是空的,但也不是所提供的选项之一。
    您需要重新查看应用程序中的流程,因为我认为您的代码与您的要求不匹配。

    我解决了它D:D:D 问题出在c:选择。。这是完全不必要的。。。 更正后的代码为

                <c:forEach items= "${cookie}" var="currentCookie">
                            <c:if test="${currentCookie.key eq 'user_type' }">
                                <c:set var="user_type" value = "${currentCookie.value.value }"/>
    
                            </c:if>
                        </c:forEach> 
    
          <c:if test="${user_type eq 'T' || user_type eq 'P'}"> 
                                 <li><a href="/myproject/f/auction_history/">My Account</a></li>
                        </c:if>                                         
                        <c:if test="${user_type eq 'D'}">
                                 <li><a href="/myproject/f/menubarCreateAuction/">Create Auction</a></li>
                        </c:if>
                        <c:if test="${user_type eq 'F'}">
                                 <li><a href="/myproject/f/menubarDfoManagement/">DFO Management</a></li>
                        </c:if>
                        <c:if test="${user_type eq 'S'}">
                                 <li><a href="/myproject/f/menubaruserManagement/">User Management</a></li>
                        </c:if>
    
    
    

  • 拉迪姆普。。谢谢你的意见……:)

    您的“测试”语法可能需要查看。请尝试
    ${user\u type eq'T}
    。注意使用
    eq
    。你也可以使用
    ==
    。实际上这里还有很多错误。您对
    的使用完全是一团糟,您嵌入的
    语句是错误的,嵌套时没有包装
    ,然后您对排序列表的要求有点奇怪,因为您要么有一个值,要么有3个值,但就是这样。
                <c:forEach items= "${cookie}" var="currentCookie">
                            <c:if test="${currentCookie.key eq 'user_type' }">
                                <c:set var="user_type" value = "${currentCookie.value.value }"/>
    
                            </c:if>
                        </c:forEach> 
    
          <c:if test="${user_type eq 'T' || user_type eq 'P'}"> 
                                 <li><a href="/myproject/f/auction_history/">My Account</a></li>
                        </c:if>                                         
                        <c:if test="${user_type eq 'D'}">
                                 <li><a href="/myproject/f/menubarCreateAuction/">Create Auction</a></li>
                        </c:if>
                        <c:if test="${user_type eq 'F'}">
                                 <li><a href="/myproject/f/menubarDfoManagement/">DFO Management</a></li>
                        </c:if>
                        <c:if test="${user_type eq 'S'}">
                                 <li><a href="/myproject/f/menubaruserManagement/">User Management</a></li>
                        </c:if>