Organizational Research By

Surprising Reserch Topic

how to iterate an object in jsp to get the percentage


how to iterate an object in jsp to get the percentage  using -'java,html,jsp,servlets,percentage'

I am working on servlet and jsp project. I am passing an object from servlet to JSP. And currently I am iterating that object and showing them in a table -

Below is my code in jsp -

<TABLE id="tableSMS" BORDER="1" CELLPADDING="3" CELLSPACING="1" style="text-align: center;">
    <TR style="color:#ffffff;background-color:#787878;">
        <TH>Hash Name</TH>
        <TH>Database Name</TH>
        <TH>Version</TH>
    </TR>
    <c:forEach var="i" begin="0" end="${reportCount.getHash().size() - 1}">
        <TR>
            <TD>
                    ${reportCount.getHash().get(i)}
            </TD>
            <TD>
                    ${reportCount.getDatabaseName().get(i)}
            </TD>
            <TD>
                    ${reportCount.getVersion().get(i)}
            </TD>
        </TR>
    </c:forEach>


And above code is working fine and I am able to show the data properly. Now what I need to do is -

${reportCount.getDatabaseName().get(i)} will return database name as oracle or mysql only. Now I need to calculate what is the percentage of oracle database. I will get the total number of records from ${reportCount.getHash().size(). So if total number of records is 10 and oracle database is present 5 times, then the percentage should be 50%.

Now I am not sure how would I calculate the above percentage using that object? And after calculating that percentage, I need to show the result in a new table which is shown below -

      <table>
          <tr>
          <th style="background-color: #E8E8E6;"><b>Oracle Database</b></th>
          </tr>
          <tr>
              <!-- I would like to show the percentage in this row -->
              <td>%</td>
          </tr>
      </table>


I am thinking I should iterate the reportCount object again in the above new table and extract the percentage here but not sure how would I do that? Can anyone provide an example?

UPDATE:-

Here is my bean code -

public class Response {
    private List<String> hash = new LinkedList<String>();
    private List<String> databaseName = new LinkedList<String>();
    private List<String> version = new LinkedList<String>();

    // getters and setters here

}

    
asked Oct 19, 2015 by bhavin
0 votes
5 views



Related Hot Questions



Government Jobs Opening

what to do is defined here


answered Oct 19, 2015 by deepak07.s

...