【发布时间】:2014-02-27 05:11:40
【问题描述】:
我有三个cookie,其中两个用于保存用户的详细信息(名称和id),另一个用于保存用户的类型。我需要根据从其中一个 cookie 中检索到的用户类型显示特定消息。
我有以下工作代码,但它有点复杂,我想知道是否有任何有效的方法来做到这一点。
<c:forEach items="${cookie}" var="IdCookie">
<c:if test="${IdCookie.key == 'UserID'}"> << if UserID cookie is found
<c:forEach items="${cookie}" var="nameCookie">
<c:if test="${nameCookie.key == 'User'}"> << if User cookie is found
<p>${IdCookie.value.value} ${nameCookie.value.value}</p>
<c:forEach items="${cookie}" var="typeCookie">
<c:if test="${typeCookie.key == 'Type'}"> << if Type cookie is found
<c:if test="${typeCookie.value == 'One'}">
<p>,Your type is one </p>
</c:if>
<c:if test="${typeCookie.value == '0'}">
<p>,Your type is NOT one </p>
</c:if>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
输出
Cookies' values >> 1 Alex 0
output >> 1 Alex,Your type is Not one
Cookies' values >> 1 Jack One
output >> 1 Jack,Your type is one
【问题讨论】:
-
第一件事是为输出的每个部分设置单独的 for 循环,以使其更简单。