title: Verifying Cookies in JSP using JSTL
body: <p>I'm trying to figure out how cookies can be used to prevent a hacker from typing in a URL to an internal part of a java web application that shouldn't be accessible unless the user is logged in.</p>
  
  <p>For example, I'd like to prevent a hacker from typing in <a href="http://domain.com/myapp/listtable.jsp" rel="nofollow">http://domain.com/myapp/listtable.jsp</a> and be able to view the table without logging in.</p>
  
  <p>I have a servlet which stores a list of all cookies it has handed out to clients. I'm struggling to understand what the JSP/JSTL code would look like to examine the cookies in the request and compare it to what the server has stored. </p>
  
  <p>Something like:</p>
  
  <pre><code>    &lt;c:forEach items="${cookie}" var="currentCookie"&gt;  
  
          &lt;!-- Compare each incoming cookie with the cookies kept in the servlet,
               if there's not a match then redirect to the login page. Otherwise,
               show the contents of the page below --&gt; 
  
      &lt;/c:forEach&gt;  
  
  &lt;html&gt;
  
      --- main page HTML here
  </code></pre>
  
  <p>Can anyone give me some advice on how to do this?</p>