File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Making and filling a table" Watch "Making and filling a table" New topic

Making and filling a table

Darko Markovic

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: 245

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

Joined: Jan 10, 2002
Posts: 63844

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] [About Bear] [Books by Bear]
Darko Markovic

Joined: Sep 15, 2013
Posts: 16

I figured it out, but thanks anyway :D
I agree. Here's the link:
subject: Making and filling a table
It's not a secret anymore!