title: JSP increment table row calculate sum and back to jsp with Beans
body: <p>I got a table in JSP. there I have 3 input text with values, and when I click submit then I got again the JSP table with one row more with the result of the three input.</p>
  
  <p>index.jsp this jsp is where I got the table with the values and sum then I submit to servlet</p>
  
  <pre><code>&lt;form method="post" action="Servlet"&gt;
          &lt;table id="sum_table"&gt;
            &lt;tbody&gt;
            &lt;tr&gt;
                          &lt;td class="numtotal"&gt;TOTAL&lt;/td&gt;
                          &lt;td class="num"&gt;1&lt;/td&gt;&lt;td class="num"&gt;2&lt;/td&gt;&lt;td class="num"&gt;3&lt;/td&gt;&lt;td class="num"&gt;
                      &lt;/tr&gt;   
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="text" value="${bean.sum}"maxlength=3 readonly="readonly"&gt;&lt;/TD&gt;
                  &lt;c:forEach items="${bean.values}" var="value" varStatus="loop"&gt;
                      &lt;c:if test="${not loop.first and loop.index % 3 == 0}"&gt;
                          &lt;/tr&gt;&lt;tr&gt;
                      &lt;/c:if&gt;
                      &lt;td&gt;&lt;input type="text" name="value" value="${value}"  maxlength="2"/&gt;&lt;/td&gt;
                  &lt;/c:forEach&gt;
              &lt;/tr&gt;
            &lt;/tbody&gt;
          &lt;/table&gt;
               &lt;p&gt;&lt;input type="submit" id="submit"/&gt;&lt;/p&gt;
               &lt;p&gt;&lt;input type="button" id="btnAdd" value="+"/&gt;&lt;/p&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Servlet.java Here I set the values and the sum of values and send to the index jsp</p>
  
  <pre><code>Bean bean = new Bean(); 
          String[] values= request.getParameterValues("value");
  
          if (values == null) {
              values= new String[3];
              for(int i=0; i&lt; 3;i++) {
                  values[i]= "0";
              }
          }
          Integer sum= 0;
          for(int i = 0; i &lt; values.length; i++)
          {
              bean.setSum(sum = sum + Integer.valueOf(values[i]));
              bean.setValues(values);
          }   
           request.setAttribute("bean", bean);
              request.getRequestDispatcher("/index.jsp").forward(request, response);
  </code></pre>
  
  <p>This is my bean Class:</p>
  
  <pre><code>public class Bean {
  
      String[] values;
      Integer sum;
  
      public Integer getSum() {return sum;}
      public void setSum(Integer integer) {this.sum = integer;}
  
      public String[] getValues() {return values;}
      public void setValues(String[] valores) {this.values= values;}
  
  }
  </code></pre>
  
  <p>With one row works ok example:</p>
  
  <pre><code>TOTAL | VALUE1 | VALUE2 | VALUE3
   10   |    2   |   3    |  5
  </code></pre>
  
  <p>But If I do a button that increment this row for do another sum, of three more values is that possible?</p>