wood burning stoves 2.0*
The moose likes JSP and the fly likes Making and filling a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Making and filling a table" Watch "Making and filling a table" New topic
Author

Making and filling a table

Darko Markovic
Greenhorn

Joined: Sep 15, 2013
Posts: 16

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.


One cannot simply use scriptlets in JSP. And also, mycaruba.
Ahsan Bagwan
Ranch Hand

Joined: Oct 05, 2010
Posts: 157
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

Joined: Jan 10, 2002
Posts: 60799
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Darko Markovic
Greenhorn

Joined: Sep 15, 2013
Posts: 16

I figured it out, but thanks anyway :D
 
 
subject: Making and filling a table
 
Similar Threads
How do you copy data from one database to another
SQL Query
Simple RDBMS question
can i use one entity bean to access more than one tables
[ProgrammerSeeksPattern] synchronize data