You do mean an HTML table?
Then create a class to represent the data in each row. Populate an ArrayList of these class objects to represent the data in the table. Create a comparator and use this comparator in the Collections.sort method:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.Comparator)
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Comparator.html
tolmank , has suggested a good solution with JSPs and Java.
Another way to accomplish this is with XML, XSLT and JSTL XML tags.
Populate the data into an XML structure, then transform that XML structure with XSLT and inside the JSP make use of JSTL XML tags to call the transformation.
You can pass the sort-by field as an input parameter to the XSLT via JSTL XML tags used to transform the XML into HTML table.