aspose file tools*
The moose likes JSP and the fly likes populating HTML tables in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "populating HTML tables in JSP" Watch "populating HTML tables in JSP" New topic
Author

populating HTML tables in JSP

munish plaza
Greenhorn

Joined: Sep 25, 2003
Posts: 2
Hi,
I am required to get data from a server and populate it into a HTML table.The data can go upto 1000 rows.
If I have a code some thing like this(this is just a pseudo code)
<table border="1">
<% for(int j=0; j<hashtable.length; j++){ %>
<TR id>
<TD > <%=hashtable[j]%> </TD>

</TR>
<% } %>
</table>
How effective from performance point of view is the usage of for loop.
My data is contained in a hash table.What is the best approach that i can use.
Please help
Thanks
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

May I know why are you using hashtable and not hashmap? Hashmap methods are not synchronized and hence perform better.


Groovy
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30752
    
156

Is your data stored in a HashTable (java class) or array named hashTable. From your code, it looks like you have an array.
If you are using an array, the for loop is effective. If you are using a HashTable, the syntax is wrong.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by Jeanne Boyarsky:
Is your data stored in a HashTable (java class) or array named hashTable. From your code, it looks like you have an array.
If you are using an array, the for loop is effective. If you are using a HashTable, the syntax is wrong.

Oops..It is an array and hot Hashtable
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
For loop is effective if you have relatively large amounts of data.
If the number of records is known at compile time and you don't mind hardcoding that and writing a lot of duplicate code it's from a performance point better to unroll the loop.
But a loop is of course more flexible...
It's faster to (if possible) determine the actual length before entering the loop and setting that as the terminator rather than a function.
Saves a few clockticks on each iteration but is errorprone if the size of the array iterated over can change during the iteration (which can get ugly, but can be necessary).


42
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

It's faster to (if possible) determine the actual length before entering the loop and setting that as the terminator rather than a function.

Since array length is obtained from a field rather than a method it does not make any difference, i guess.
If ordering is not important reverse looping an array will be better.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: populating HTML tables in JSP