File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Jsp Table printed in wrong way

Rakesh Keerthi
Ranch Hand

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


[Thumbnail for output.JPG]

[Thumbnail for Expected.JPG]

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

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] [About Bear] [Books by Bear]
Stefan Evans

Joined: Jul 06, 2005
Posts: 1580
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: 149
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
I agree. Here's the link:
subject: Jsp Table printed in wrong way
It's not a secret anymore!