• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying multiple columns in html table in jsp from mysql database

 
Kenneth Owino
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

This is the JSP:



And the DAO that accesses the database:



And the DTO:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65119
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post an SSCCE of your issue. You've posted way too much unnecessary code to wade through.
 
Kenneth Owino
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


How do I add the column under header
 
Stefan Evans
Bartender
Posts: 1780
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two DTOs? One for firstname, one for lastname?

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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic