File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Data Alignment  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Data Alignment  " Watch "Data Alignment  " New topic
Author

Data Alignment

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi Ranchers
I'm displaying data using JSTL and JSP by fetching data from the database(back-end, Servlets and Beans). I'm able to display the data successfully but the problem is the alignment of the data. Here's a piece of code from JSP:


Now the data is getting displayed vertically while the table is horizontal. I mean, the headers of the table are Name and Age and the fetched from the db is getting displayed under the Name header only.. i.e. Under Name header itself Age(along with Name) is also getting displayed. I want Name to be displayed under Name header and Age to be displayed under Age.

I know that it is a simple task in HTML but have no idea how to display the same using JSTL. This may be a silly question but any help in this regards would be much appreciated.


Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

All that matters to the browser is the HTML that is sent to it. Do a View Source at the browser to see what's being sent. Is it correct?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60800
    
  65

Hint: you are only creating one <td> so how could you expect two columns?
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi Bear
The View Source seems to be weird. Here's the View Source:


Is my code incorrect ?
And I'm fetching data using a loop, so how can I use 2 <td> ? If I use it twice then both the fields are displaying twice.


Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

well, How you set the Name and Age in request scope(to display that on front end ). can you post the code?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Anyway i tell you the way,


in servlet (backend):

set the bean value into List like below




in jsp display like below:




And ,Swapna i encourage you to use jstl


Hope this helps

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Swapna Gouri Kalanidhi wrote:Hi Bear
The View Source seems to be weird. Here's the View Source:


Are you serious? That's just the source of an ordinary HTTP 405 error.
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
@ SeethaRaman
My code is almost similar to the one you have posted. The only difference is the data being fetched from the database. Here's the code:

This is a code snippet from the bean class. And yes, I have setters and getters too...


@ Bauke
Yes, I'm dead serious, that's what is getting displayed as the page source on the browser. But why is it displaying that way? Is it a problem with my code or with my browser? I'm really confused. :roll:
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
@Bauke
If that's the source for 404 error, then how am I able to view the desired output? This is even more confusing.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Swapna Gouri Kalanidhi wrote:@Bauke
If that's the source for 404 error, then how am I able to view the desired output? This is even more confusing.

Look, it's a 405, not a 404. Look like that your webbrowser fires a brand new GET request on view source of a POST. Try another webbrowser.

That headbanging isn't needed dude. That smiley annoys me.
Vadim Vararu
Ranch Hand

Joined: Jan 03, 2009
Posts: 147
The first problem is in you first code snippet. You have two columns in the upper row and just one in the bottom row. After the next HTML result you've given us, we can conclude that you have another problem that has nothing to do with columns and even with HTML markup.

P.S. Tomcat generates an extremely ugly error page html markup


If you think you've done too much, usually it means you've done too few.
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
@ Bauke
Yes, that seems to be a problem with my browser. I was using Google Chrome and when I tried with IE, I faced no problems. I'm able to view the same HTML code that I have written.
And sorry, for that smiley that annoyed you.

@ Vadim
Yes, after viewing the page source, I understood where the problem is. Will modify the code and get back if I have any doubts.

Thanks all for helping me...!
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Yes, after viewing the page source, I understood where the problem is. Will modify the code and get back if I have any doubts.

Thanks all for helping me...!
You're welcome.
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
This time I'm facing a different error if I try to access the attributes individually. Here's what I'm doing exactly.

Bean class:

The other part of the code was already posted by me, refer the method getCSVDData() in the thread above.

Servlet class:

Now I have modified the JSP a little bit:

Now when I use value.dispatchDate, am getting this HTTP 500 error:

It's clearly saying that it's not able to find the attributes. How should I handle this error?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi swapna,


i mentioned that already about naming convention of bean method




if you make this, code should work.
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
@SeethaRaman
I have tried all possible combinations to get the output but still getting the same error.

I'm not able to understand why that error is popping up. How should I move forward from here? :roll:

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

ohhhhh.... sorry , i did not see your bean class properly ops: . if this is your java bean methods



then you need to do this



and also let me know, if problem is not solve
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hello SeethaRaman
I'm getting the same error still.

What should I do now? I'm not able to make out where the error is lying. I'm afraid if I have coded improperly or have made any silly mistake. :roll:

I really appreciate your patience and help that you are lending me to solve this problem. Thanks a bunch !
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Swapna Gouri Kalanidhi wrote:
I'm afraid if I have coded improperly


yes.

here(in your getCSVMethod) you are not using the javabean.



you need to do some thing like this



Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Here's the servlet code:

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

hi, see my previous edited post . you are not setting the values into your javabean. got it?
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Yeah, I got it. But now am facing a different problem. The intensity is less, though. The setXXX() methods seem to accept only boolean, but what I'm trying to add are Strings. And because of this am getting errors that it cannot take String arguments. If this is the case then I need to change the return type of setters and getters too.

Is "Bean" a predefined class in Java, that I need to import for my purpose? I mean do I need to call the constructor of this predefined Bean class, if one exist, to solve this problem? I have seen something called as "Beans" class but not a "Bean" class. Now what should I do to get rid of this new error? Should I change the return types of my setters and getters to boolean? I don't think this will work, though.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

hi swapna,

Here i mean ,Bean means TransferObject. your java class here is fine. i dont see any boolean return type . and also you go through my 2nd post of this tread .

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi Seetharaman

Thanks a bunch ! I'm able to display the data successfully.

I have done some simple mistakes due to which a few errors popped up. Now the data is getting displayed very well.

Thanks a lot ! You have helped me a lot, took a lot of pain in explaining me minute details with lot of patience. Thanks a ton !!!
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Swapna Gouri Kalanidhi wrote: Thanks a ton !!!


You are Welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data Alignment
 
Similar Threads
Table data display with JSTL in a JSP
displaying multiple columns in html table in jsp from mysql database
Convert JSTL variable type
dynamic text box value into database
Help me in send redirct