title: How to check user is logged in or not in Java EE
body: <p>I use the Struts2 framework. In jsp, I show a login box in my project and when the user clicks on a login button, I set a cookie with the name "loggedin" and set its value to "true" in an Action Class.</p>
  
  <p>Then returning "success" will load this login page again.</p>
  
  <p>In login page:</p>
  
  <pre><code>&lt;body&gt;
  &lt;%
  Cookie cookie[] = request.getCookies();
  for( c : cookie )
  {
   if( c.getName().equals("loggedin") )
   {
    if( !c.getValue().equals("true") )
    {
  
  %&gt;
  //show login form here.
  
  &lt;%
  
    }//end inner if
  
    else //if cookie "loggedin" value is "true"
    {
  
  %&gt;
  
  //show username/profile picture/logout button here
  
  &lt;%
    }//end else
   }//end outer if
  }/end for loop
  %&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I got a problem. When I this click login button in the login form, a cookie is set and the page is reloaded. But instead of a username/profile picture, the login form is still being displayed until I reload the page manually. </p>
  
  <ol>
  <li>How can I solve this? </li>
  <li>I think it's not the correct way to check logged in or not. Can somebody please tell me how to check this in another way?</li>
  </ol>