title: Set color for even rows using <s:set> - Struts2
body: <p>I want to give dynamic color/style for even rows of the table. Below is my code but it is not giving me required output.</p>
  
  <pre><code>&lt;table&gt;
     &lt;s:iterator value="allMonths" status="incr"&gt;
     &lt;style&gt;
      .evenRow{background-color: yellow;}
      .oddRow{background-color: orange;}
     &lt;/style&gt;
     &lt;tr&gt;
  
     &lt;s:if test="#incr.count%2 ==0"&gt;
      &lt;s:set var="clr" value="evenRow"&gt;&lt;/s:set&gt;
     &lt;/s:if&gt;
  
     &lt;s:else&gt;
      &lt;s:set var="clr" value="oddRow"&gt;&lt;/s:set&gt;
     &lt;/s:else&gt;
  
          &lt;td class="%{#clr}"&gt;Month:&lt;/font&gt; &lt;s:property/&gt;&lt;/td&gt;
          &lt;%-- &lt;td class="%{clr}"&gt;Month:&lt;/font&gt; &lt;s:property/&gt;&lt;/td&gt; --%&gt;
          &lt;%-- &lt;td class="clr"&gt;Month:&lt;/font&gt; &lt;s:property/&gt;&lt;/td&gt; --%&gt;
      &lt;/tr&gt;
     &lt;/s:iterator&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>    &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;s:form action="clickAction"&gt;
  
      &lt;s:textfield name="beanobject.uname" label="Enter Username" /&gt;&lt;br&gt;
      &lt;s:textfield name="beanobject.age" label="Enter Age" /&gt;&lt;br&gt;
      &lt;s:textfield name="beanobject.sex" label="sex" /&gt;&lt;br&gt;
      &lt;s:submit value="Submit" align="center" /&gt; 
      &lt;s:submit value="Clear" align="center" action="clearAction"/&gt;
  &lt;/s:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>MyAction.java</strong></p>
  
  <pre><code>    ---imports---
  
  public class MyAction extends ActionSupport{
      private MyBean beanobject;
      private List&lt;String&gt; allMonths;
  
      //Getters &amp; Setters
  
      public String execute(){    
          System.out.println("execute");
          return SUCCESS;
      }
  
      public String click()
      {   
          allMonths = new ArrayList&lt;String&gt;();
          allMonths.add("Jan");
          allMonths.add("Feb");
          allMonths.add("Mar");
          return SUCCESS;
      }
  
      public String clear(){
          return SUCCESS;
      }
  }
  </code></pre>
  
  <p>I also tried using <strong>"bgcolor"</strong> attribute but with no success. What am I missing?</p>
  
  <p><em>Provided required code. I am just hardcoding values in list in ActionClass</em></p>