Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp Table printed in wrong way

 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the below code in my jsp.




and the output is as in Screen 1 but i want the output to be as in screen 2. please help me .

Thanks.

output.JPG
[Thumbnail for output.JPG]
Output
Expected.JPG
[Thumbnail for Expected.JPG]
Expected Output
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figure out what HTML will generate the table you want. Then, and only then, write the JSP code to emit that HTML.
 
Stefan Evans
Bartender
Posts: 1778
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most obvious difference between the two images is that columns and rows have been transposed.

Currently you have two nested loops
For each database column
For each database row
output the value in this column/row

I would suggest that you reverse these loops
For Each database row
For each database column
Output the value in this row/column

If you do it in that manner, you should only need one query rather than two, as iterating rows then columns is the natural access for a database query.

Think about what you want to output when a value is null.

Also, if you've read any other posts in this forum, you will have discovered
- java code in a JSP is frowned upon. Java code belongs in a java class. Use JSTL/EL in JSPs
- sql code does not belong in a JSP. You should run the query, load the results into a java data structure (e.g. List of objects) , and then pass that List to your JSP to display.

 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear and Stefan,

i've fixed it it was actually a formatting problem. your tips helped me. And below is the code(a reference, just in case if anybody faces the similar issue).





Thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic