• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

table element repeats for multiple rows in JSP

 
Poonam Dhatavkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Poonam Dhatavkar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh..Thank you.
I will surely try improving. Any more suggestions ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Bear Bibeault :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic