aspose file tools*
The moose likes JSP and the fly likes Passing a list of beans from a servlet to jsp page to display in html table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Passing a list of beans from a servlet to jsp page to display in html table" Watch "Passing a list of beans from a servlet to jsp page to display in html table" New topic
Author

Passing a list of beans from a servlet to jsp page to display in html table

Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
Hi everyone! Lurking around for some time and I finally have a need to make a post.

Forgive me I am not very experienced in programming yet.

I have a program I am building that when you click a menu item, goes to a servlet.
The servlet calls a java class that opens a connection to a database, runs a query and loops through every row in the table.
For every row, the data is stored in a bean.
The beans get added to a list.
The list is sent back to the servlet.

Now I wish to send the list of beans to a jsp page for display.

I am inexperienced with Java Beans and do not wish to use jstl to manipulate the list in jsp if I can do so with mere bean tags.

So how do you manipulate a list of beans if I wanted to make an html table row for every bean in my list?

can I only reference a single bean with <jsp:usebean ?

again, forgive my ignorance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

Jesse Snadden wrote:
I am inexperienced with Java Beans and do not wish to use jstl to manipulate the list in jsp if I can do so with mere bean tags.

Your inexperience is showing. Using the JSTL is the way to do this. Any other way is not only more difficult, but error-prone and antiquated. What's your beef with the JSTL?

So how do you manipulate a list of beans if I wanted to make an html table row for every bean in my list?

I'll pretend you didn't dis the JSTL... You'll place the list of beans in request scope and then reference this list using the <c:forEach> JSTL tag.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
No beef with jstl. What I want to avoid is using a lot of scriplets in the jsp page if possible. I don't get the jsp:usebean and/or jsp:getProperty tags.

Dunno... someone once told me my use of scriplets was gross and that I should be using bean tags.

So you are saying I should not be be doing anything different than this ?(snippet of old code of mine):


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

Jesse Snadden wrote:No beef with jstl. What I want to avoid is using a lot of scriplets in the jsp page if possible.

Umm, that is exactly what the JSTL does! Without the JSTL, you need to use scriptlets, which you are correct in avoiding like the plague.

I don't get the jsp:usebean and/or jsp:getProperty tags.

getProperty is outdated. Not needed when using JSTL and EL. useBean has limited use.

Dunno... someone once told me my use of scriplets was gross and that I should be using bean tags.

Scriptlets are gross. But using bean tags in place of them might have been true 9 years ago. Modern JSP uses JSTL and EL.

So you are saying I should not be be doing anything different than this ?(snippet of old code of mine):

No, I am not saying that. The scriptlets in that code need to be fed to the shredder. There should be no Java code in a JSP. None. Nada. Zero. Zilch.

Why on earth are you mixing scriptlets in with the JSTL and EL?

The setting of the scoped variables (via setAttribute()) should be taking place in the controller, not the page.
Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
I would appreciate it if you would remain patient with me. "umms" in sarcastic tones does nothing but belittle me ...

I've obviously gotten confused about something and would appreciate if you could either point me in the right direction or show me an example. I came to this forum for some help afterall. I don't have 10 years of experience. I'm really new at this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

Jesse Snadden wrote:I would appreciate it if you would remain patient with me. "umms" in sarcastic tones does nothing but belittle me ...

Only if you take it that way.

I've obviously gotten confused about something and would appreciate if you could either point me in the right direction

That's exactly what I am doing. Scriptlets and the bean tags are yesterday's news.

Today, it's all about the JSTL and EL. So except for the scriptlets in the code snippet you posted, it looks like you're on the right track.

Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
Ok... bear with me (pun intended). What is EL?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

I'm off to bed, but in the meantime, you might want to read this article if the concept of controllers is new or unclear to you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

Jesse Snadden wrote:Ok... bear with me (pun intended). What is EL?


The Expression Language. The expressions in your code delimited by ${ } are EL expressions.

The EL and JSTL work hand-in-hand to add the dynamic elements to JSP pages.
Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
Bear Bibeault wrote:I'm off to bed, but in the meantime, you might want to read this article if the concept of controllers is new or unclear to you.


Thanks
Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
Bear Bibeault wrote:
Jesse Snadden wrote:Ok... bear with me (pun intended). What is EL?


The Expression Language. The expressions in your code delimited by ${ } are EL expressions.

The EL and JSTL work hand-in-hand to add the dynamic elements to JSP pages.


Ah ok... I get confused with lots of acronyms... I have plenty of those where I work already.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61190
    
  66

And if you want to know more about how JSPs work, this article might also be interesting.
Jesse Snadden
Greenhorn

Joined: May 16, 2011
Posts: 13
Bear Bibeault wrote:And if you want to know more about how JSPs work, this article might also be interesting.


Thanks again. I'll read that tomorrow. I'm off to bed too.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing a list of beans from a servlet to jsp page to display in html table