【问题标题】:How to put the value of a cookie into a variable of type <c:set> from JSTL?如何将 cookie 的值放入来自 JSTL 的 <c:set> 类型的变量中?
【发布时间】:2014-02-25 18:46:23
【问题描述】:

如何获取以下cookie的值并将其放入变量Cli中?

<% Cookie cookies[] = request.getCookies();
    for (int i = 0; i < cookies.length; i++) {
        if (cookies[j].getName().equalsIgnoreCase("Jack")) {
             <c:set var="Cli" value="cookies[j].getValue()"/>              
        }
    }    
%>

【问题讨论】:

  • 不惜一切代价避免使用 scriptlet。仅在 JSP 中使用 EL 和 JSTL。
  • 那么请看here
  • @SotiriosDelimanolis 你能给我举个例子吗?

标签: java jsp cookies struts2


【解决方案1】:

基本使用Retrieving cookie and array values in JSTL tags的货:

<c:forEach items="${cookie}" var="currentCookie">  
  <c:if test="${currentCookie.value.name == 'Jack'}">
    <c:set var="Cli" value="currentCookie.value.value"/>
  </c:if>
</c:forEach>

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多