Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display 2 ArrayLists in HTML table

 
Kyupa Supa
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic