>>>>> "Shawn" == Shawn Bayern <[EMAIL PROTECTED]> writes:

    Shawn> On Thu, 21 Mar 2002, Matt Raible wrote:
    >> Is it possible to do the following with JSTL?
    >> 
    >> <c:if test="${cookie.username == 'learner'}">
    >> learner
    >> </c:if>

    Shawn> Ah, I was hoping someone would ask.  The answer is "no, not exactly like
    Shawn> that," but you can still use JSTL to access cookies.

    Shawn> While web developers often have the urge to access a cookie by name, it's
    Shawn> an urge that's best to resist; cookies aren't identified by name alone,
    Shawn> but by name, domain, path, and security status.  Thus, the best way to
    Shawn> access a cookie is to loop over the list of available cookies, matching
    Shawn> the one that you're interested in.

    Shawn> Now, if you're just interested in name, that's fine; but JSTL doesn't go
    Shawn> out of its way to support that special case.  Instead, you can just write

    Shawn>   <c:forEach items="${pageContext.request.cookies}" var="cookie">
    Shawn>     <c:if test="${cookie.name == 'learner'}">
    Shawn>       <c:set var="cookieValue" value="${cookie.value}" />
    Shawn>     </c:if>
    Shawn>   </c:forEach>

Curious.  Not that I would necessarily want to do this, but from the JSTL
specification, it almost seems like you could do something like this:

  <x:set var="username" select="$cookie:username"/>
  <c:if test="${username == 'learner'}">

So it appears that simple access to cookies is in the XML tags, but not the
core tags?  Please correct me if I'm confused (likely).

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to