Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

javaBeans

 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and cow tipper
Posts: 5001
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tutorial: http://java.sun.com/docs/books/tutorial/javabeans/
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic