title: Comparing Strings in Struts2 <s:if> Tag
body: <p>I have an <code>index.jsp</code> page wherein certain elements turn on/off depending on whether the user has logged in or not.</p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;head&gt;
      &lt;s:set var="accessType" value="GUEST" /&gt;
      &lt;s:if test="#session.containsKey('currentAccessType')"&gt;
          &lt;s:set var="accessType" value="#session.currentAccessType" /&gt;
      &lt;/s:if&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;nav&gt;
          &lt;s:if test="#accessType.equals('GUEST')"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.jsp"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Login&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="http://www.mywebsite.com" target="_blank"&gt;Main Site&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/s:if&gt;
  
          &lt;s:else&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.jsp"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Control Panel&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Logout&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="http://www.mywebsite.com" target="_blank"&gt;Main Site&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/s:else&gt;
      &lt;/nav&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>The <code>accessType</code> is set to <code>GUEST</code>. However, it's entering the else-block even if the user has not logged in yet.</p>
  
  <p>Did I commit an error in my String comparison?</p>
  
  <p><strong>UPDATE:</strong><br>
  I removed the session part from the index.jsp just to see and it now looks like this:</p>
  
  <pre class="lang-jsp prettyprint-override"><code>&lt;head&gt;
      &lt;s:set var="accessType" value="GUEST" /&gt;
      &lt;!-- removed session code for testing --&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;nav&gt;
          &lt;s:if test="#accessType.equals('GUEST')"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.jsp"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Login&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="http://www.mywebsite.com" target="_blank"&gt;Main Site&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/s:if&gt;
  
          &lt;s:else&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.jsp"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Control Panel&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#"&gt;Logout&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="http://www.mywebsite.com" target="_blank"&gt;Main Site&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/s:else&gt;
      &lt;/nav&gt;
  
      &lt;br /&gt;
  
      Access type is &lt;s:property value="#accessType" /&gt;.
  &lt;/body&gt;
  </code></pre>
  
  <p><strong>Problems:</strong></p>
  
  <ol>
  <li>Condition enters <code>&lt;s:else&gt;</code> block.</li>
  <li>Access type is not printing (somehow not being set).</li>
  </ol>