Hi! I'm finding trouble on how to display more than one column from mysql database table into an html table in jsp. So far I can display rows of only one column using the code below. Someone help me on how I can display say table rows from more than one column.
Ok. Thank you for the reply. Actually, I have a database table with 2 columns "firstname" and "lastname". All I need is to retrieve all the rows in these columns and display them in an html table in my JSP. I read that using JSTL is a good practice and I tried using forEach. In doing this I created 2 DTOs 1 that gets firstname and 1 that gets lastname and two respective DAOs to access the database and returns arrayLists for each of the columns. Now the problem is I'm only able to use one DAO and one DTO that displays the firstname column from the table. How can I make all the columns be displayed? This part of the JSP only displays a table with one column:
That doesn't make sense to me. If you're going to get one, you're probably going to want the other.
Why make two trips?
What I would expect is that your DAO layer would return a list of Beans, with all the attributes that you need on them.
So rather than a firstnameDTO, and lastnameDTO, I would expect a StudentDTO which has firstname and lastname attributes (and email, and student id etc etc)
Suggestions on coding style/convention
- Classes should start with a capital letter. fnmDto should be FnmDto.
- fnmDto is a horrible name anyway. I presume it is "first name data transfer object"? Just for readability use "firstName" rather than "fnm"
You then iterate over that list of StudentDTOs, and display the attributes as you wish.
subject: displaying multiple columns in html table in jsp from mysql database