title: using if else statement for dynamic table jsp
body: <p>EDIT:
  I am retrieving an arraylist of data with data like:[category,content,category,content,...],and 
  I want to display a table on a JSP page with dynamic data like this:</p>
  
  <pre><code>&lt;tr&gt;
  &lt;td align="center"&gt;
  Category of Tweets:
  &lt;/td&gt;
  &lt;td align="center"&gt;
  All Tweets of User:
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="center"&gt;
  Entertainment
  &lt;/td&gt;
  &lt;td align="center"&gt;
  Tweet Content
  &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>But using the source code I have below:</p>
  
  <pre><code>&lt;table id="table" border="1" align="center"&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  Category of Tweets:
  &lt;/td&gt;
  &lt;td align="center"&gt;
  All Tweets of User: &lt;%out.println(userName); %&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;%
  for(int i=0;i&lt;stringList.size();i++){
  %&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;%
  if(i%2==0){
  String category = stringList.get(i).toString();
  out.print(category);
  %&gt;
  &lt;/td&gt;
  &lt;%}else{ %&gt;
  &lt;td&gt;
  &lt;%
  String content = stringList.get(i).toString();
  out.print(content);
  }
  %&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;%
  }
  %&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The browser seems to duplicate extra table tags just before the else statement:</p>
  
  <pre><code>&lt;td&gt;
  
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  
  &lt;/td&gt;
  </code></pre>
  
  <p>I am lost on how to resolve this.Could anybody tell me how should I amend the code?</p>