• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Display 2 ArrayLists in HTML table

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved it:

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic