aspose file tools*
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 Soft Skills this week in the Jobs Discussion 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: 162
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: 61761
    
  67

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making and filling a table