Dhruv
Dhruv

Reputation: 1728

How to generate multiple html tables dynamically over jsp using servlets?

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.

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.

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.

here is the sample table for better understanding:-

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

like

 for(int i ; int<building.lenth; i++){
       for(int k ; i<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.
    }
    }

So the question is how should i handle this situation. What data structures can help me achieve this goal. Thanks in advance. :)

Upvotes: 1

Views: 3086

Answers (1)

atrain
atrain

Reputation: 9255

There are existing JSP taglibs to create tables on the fly based on your data. A good example is DisplayTag. You will probably find an example on the DisplayTag site of what you want to do, and will end up having more concise JSP code.

Upvotes: 3

Related Questions