title: How to generate multiple html tables dynamically over jsp using servlets?
body: <p>hey guys i have a situation in which i am getting a array string of selected building names and another array string of selected building subsystems. So based on the user selection i have to generate a report in which for each building a different table has to be created over jsp page.</p>
  
  <p>So the table should be like one building name in first column and the chosen subsystem in second column rows. Other columns have heading 2011, 2012 upto 2016.Hence there can be multiple table but with same set of subsystems at a time. The values in other blocks comes in based on some calculation. Its kind of forecast report in which if for eg. roofing for some building has renewal cost in 2011 then its value should come at right place. </p>
  
  <p>And finally i have to get the total at the bottom of each table and further a table in which must be having grand total for each column.</p>
  
  <p>here is the sample table for better understanding:-</p>
  
  <p><img src="https://i.stack.imgur.com/LlA51.png" alt="enter image description here">
  So can anyone suggest me what approach i should take. I can generate the table by using two for loops one for buildings and other for subsystem inside buildings</p>
  
  <p>like </p>
  
  <pre><code> for(int i ; int&lt;building.lenth; i++){
         for(int k ; i&lt;subsystem.lenth; i++){
        //over here i subdivide the loop into various if and else if's based on the chosen subsystem and access database everytime for each subsystem 
  and get their respective values for calculations over jsp directly. In that case i'm not able to total all the columns.
      And in all its a bad practice to access database like that from jsp and doing java over jsp.
      }
      }
  </code></pre>
  
  <p>So the question is how should i handle this situation. What data structures can help me achieve this goal. Thanks in advance. :)</p>