Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javaBeans  RSS feed

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using a JSP and a servlet How do you impliment a javaBean? I'm not really sure what a JavaBean is?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Until you know what a javabean is, it's not really time to discuss their usage in the web app environment.

So I've moved this off to the Java in general (beginner) forum to answer the question: what is a javabean?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's all sorts of uses for a JavaBean.

The bean itself is created independently of a Servlet or a JSP. It is a Java class that stands on its own. But a Servlet and a JSP will use the JavaBean, and maybe even pass the JavaBean back and forth between each other, stuffing that silly little JavaBean in an HttpSession or something.

Here's a fun little tutorial on Servlets, JSPs, and where JavaBeans and maybe even EJBs fit into the picture. I highly recommend the tutorial. The guy that wrote it is very clever.

Cheers!

-Cameron McKenzie
 
Steven Marco
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kameron McKenzie:
There's all sorts of uses for a JavaBean.

The bean itself is created independently of a Servlet or a JSP. It is a Java class that stands on its own. But a Servlet and a JSP will use the JavaBean, and maybe even pass the JavaBean back and forth between each other, stuffing that silly little JavaBean in an HttpSession or something.

Here's a fun little tutorial on Servlets, JSPs, and where JavaBeans and maybe even EJBs fit into the picture. I highly recommend the tutorial. The guy that wrote it is very clever.

Cheers!

-Cameron McKenzie


Can I think of Javabean as a "temporary storage" of the form fields for passing around JSPs and Servlets? Are we really "passing" or just referencing it?

Also do you have a link to the tutorial?
 
Sanjaya Sugiarto
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tutorial: http://java.sun.com/docs/books/tutorial/javabeans/
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steven Marco:


Can I think of Javabean as a "temporary storage" of the form fields for passing around JSPs and Servlets? Are we really "passing" or just referencing it?

Also do you have a link to the tutorial?


JavaBeans as used in the JSP also feature action code, not just data storage. Thus I may infer that the main purpose of JavaBeans is to help separate data storage and action algorithms from the presentation code (JSP). Perhaps it can be said that the JavaBeans addition to JSP is some kind of a patchup for the mess that coding everything in the JSP resulted in.

Anyone would comment on this?

Cheers.
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the information. I found the Sun tutorial really good. I always have a hard time finding things on the Sun site. I always get lost. Thanks. Now for my original question about the JSP and Servlet and the JavaBean. Is the javaBean sort of a Go Between for the JSP and the Servlet? So If i am reading this right the JSP talks to the javaBean then the JavaBean returns information then the JSP would send the returned information to the Servlet? Right?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is pretty typical:

The servlet passes the real work off to some Plain Old Java Object, which creates the JavaBean. The servlet stashes the bean on the request (or session or whatever) where the JSP can get it. The JSP extracts fields from the Bean and puts them into the HTML.

I think that's just what you thought was happening, no?
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you explained it just like I thought it worked. Now I can go and do it.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Donna, I'm glad you're in a position to go on and have fun.

I stayed out of the conversation about what a JavaBean is. With such promiscuous access to mutable content, I find them rather offensive as far as objects go. They are slightly dressed up raw data structures, necessary to provide data or component information to some frameworks, but not necessarily a "good thing". Still, I use them without guilt (but without pleasure) when some API calls for them.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stuart Ash:

Anyone would comment on this?


What you have described is their conventional usage in a Model 1 web application scenario.

In the modern accetped Model 2 scenario, beans play less of a functional role and more of a DTO (data transfer object) role between a page and its controller.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!