title: Passing data from Java Servlet to JSP multiple times
body: <p>I am new to Java servlets and JSP...</p>
  
  <p>I have created a Java servlet. Actually this is my first servlet I am working on! </p>
  
  <p>Inside of my servlet code, I have a loop. For each iteration of this loop, there are variables that will be set to different values. After each iteration of this loop ends, I want to be able to print out my variables (these variables will change with each iteration of the loop) in a HTML table as a row....</p>
  
  <p>After doing some research, it seems that I need to use a JSP page to output the variables in HTML. However, <strong>how can I send my data to the JSP page after each iteration of my loop?</strong></p>
  
  <p>pseudocode example: </p>
  
  <p>--servlet logic</p>
  
  <pre><code>   forloop{
         var1 = "somedata";
         var2 = "somemoredata";
      }
  </code></pre>
  
  <p>--jsp logic</p>
  
  <pre><code> //this part should only output once   
  &lt;table&gt;
      &lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
  
      //this part needs to output everytime the JSP is called. And each time, different values of var1 and var2 will be passed 
      &lt;tr&gt;
      &lt;td&gt;${var1}&lt;/td&gt;
      &lt;td&gt;${var2}&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;/table&gt;
  </code></pre>
  
  <p>Does anyone know the best method to do this? 
  If I am going about this the wrong way, is there another approach I should take? Should I use AJAX to continue feeding information to update my page?</p>
  
  <p>Thank you for any advice and insights!</p>