wood burning stoves 2.0*
The moose likes JSP and the fly likes Jsp Table printed in wrong way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp Table printed in wrong way" Watch "Jsp Table printed in wrong way" New topic
Author

Jsp Table printed in wrong way

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 136
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.




[Thumbnail for output.JPG]


[Thumbnail for Expected.JPG]

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Figure out what HTML will generate the table you want. Then, and only then, write the JSP code to emit that HTML.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
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

Joined: Jul 16, 2012
Posts: 136
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
 
Don't get me started about those stupid light bulbs.
 
subject: Jsp Table printed in wrong way
 
Similar Threads
Getting elements by id
How to get all dropdown values
problem in retrieving data from a DB to HTML through JSP
How to get all dropdown values
How to replace a null with blank in jsp table