在jsp页面读cookie的方式常用的就两种了。
1.js
2.java // <%%>形式
今天发现另一种:JSTL // 记得jsp页面导入taglib
语法:${cookie['name'].value} // 如:<c:out value="${cookie['name'].value}"></c:out> // 张三
// 我今天的应用
这次的项目中用了struts2. 大量的地方用到了 <s:if test='...'></s:if>.不好利用cookie里的值做if...else处理.
jstl可以做到:
<c:if test=''${cookie['name'].value != null} ">哈哈</c:if>
或 <c:choose>
<c:when test=" ${cookie['name'].value} != null">欢迎...</c:when>
<c:otherwise>对象为空</c:otherwise>
</c:choose> // 相当于if... else ...