我有三个cookie,其中两个用于保存用户的详细信息(名称和ID),另一个用于保存用户的类型。我需要根据从其中一个cookie检索到的用户类型显示特定的消息。如何使用JSTL读取三个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循环,以使它更简单。 – J888