wood burning stoves 2.0*
The moose likes JSP and the fly likes table element repeats for multiple rows in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "table element repeats for multiple rows in JSP" Watch "table element repeats for multiple rows in JSP" New topic
Author

table element repeats for multiple rows in JSP

Poonam Dhatavkar
Greenhorn

Joined: Jan 11, 2013
Posts: 19
I am implementing 'Search' operation on database using jsp and displaying results in html table.
On jsp page, user 1st enter Column value like id/name and the entire row related to that input should display for further queries like update/delete.
All working fine when displaying one search result/row, bt when there are more than 2 rows to display, it repeats the table display with table head like
--------------
| id |name|
---------------
| 2 | abc |
--------------
| id |name|
--------------
| 3 | xyz |
--------------

How to avoid it ?

Code is sumthing like this

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Java code and results sets in a JSP?

Bad bad practice. The database code should be in the model and you should be using the JSTL and EL in the JSP. See this JspFaq entry for more information.

That said, the table element is inside the loop, so of course it's going to be repeated.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Poonam Dhatavkar
Greenhorn

Joined: Jan 11, 2013
Posts: 19
ohh..Thank you.
I will surely try improving. Any more suggestions ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Once you have switched to using JSTL, it's easier to see the loops using the <c:forEach> tags and less likely to have these kinds of problems.

If you need some background on how to structure modern web apps, please read this article.
Poonam Dhatavkar
Greenhorn

Joined: Jan 11, 2013
Posts: 19
Thank you very much Bear Bibeault :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: table element repeats for multiple rows in JSP