• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making and filling a table

 
Darko Markovic
Greenhorn
Posts: 16
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that takes some data from an SQL database. How do I generate a table in the same page and put the information from the database in it?
The table should have 2 columns and 5 rows.
 
Ahsan Bagwan
Ranch Hand
Posts: 254
1
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A nice way would be to bound your object (containing the data from the db) to the request scope and forward it to a JSP using RequestDispatcher

And in your JSP retrieve it using scriptlets (its use is considered bad practice) or using JSTL.

Regarding using JSTL, I am new to using it so wait for some resident expert to drop by.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand how to properly structure a web application. That means no database access in the controllers or views, and no Java code int he JSP.

The database access should be performed by model classes, which are called by the page controller. The obtained data is placed in request scope by the controller, which then forwards to the JSP, which uses JSTL and EL to construct the required HTML.
 
Darko Markovic
Greenhorn
Posts: 16
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out, but thanks anyway :D
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic