aspose file tools*
The moose likes JSP and the fly likes Display 2 ArrayLists in HTML table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Display 2 ArrayLists in HTML table" Watch "Display 2 ArrayLists in HTML table" New topic
Author

Display 2 ArrayLists in HTML table

Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
I need some help with m school project.

I have 2 ArrayLists of object. One is with Student objects, one is with Course objects.

Each ArrayList contains actually a table from the DB(teacher said to do as so).



I need to display the 2 tables(the 2 ArrayLists) in a HTML table.

This code returns only the table header.



Thank you in advance!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2861
    
  11

Where are courses and students coming from? Are you sure they contain any data? Your logic is also a bit funny. You want multiple rows inside the table, but your <tr> starts outside of the loop, so you will always have exactly one, and if courses and students have more than one element each, you're going to get a lot more <td> on that row than you expect. Are you sure you have to display both sets in a single table?

Also, just to satisfy my curiosity, did your teacher tell you to use scriptlets?
Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
In a java file I retrieve students from the database and insert them into ArrayList called "students". I retrieve courses from the database and insert them into ArrayList called "students".

I have 2 JSP files which display 2 forms, one for students and one for courses. User types there courses and students. Then they are inserted into database and ArrayLists via methods in the java files.

In this JSP file I posted here I retrieve the students and courses from the 2 ArrayLists and display them into a HTML table. I mean I'm TRYING that :p
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2861
    
  11

OK, so student and courses are being loaded from the database in Java code, but how do they get to your JSP? And what triggers them to be loaded? Are you sure that part is happening and is working correctly?

The only way showing students and courses in a single table makes sense to me is if you were showing the students enrolled in the courses. In that case, your Java code that loads from the database would be running a join query, which would associate data from the STUDENT table and the COURSE table, probably using an ENROLLMENT link table. Does that sound like something that was part of the assignment?
Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
I solved it:

 
Consider Paul's rocket mass heater.
 
subject: Display 2 ArrayLists in HTML table