Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why we need javabeans?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
we are able to connect to the database by using jdbc in jsp and servlets. Then what is the necessity of javabeans in jsp and servlets for getting date from the database?

Pls explain.....
 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Bear edit: uncited copy removed.]
[ December 28, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67750
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
Jigar Naik, when you copy information from another site, either provide a link or give credit to the source where you found the information. Copying information and passing it off as your own is not an ethical action.
 
Bear Bibeault
Sheriff
Posts: 67750
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
suseela surendra,

"Pls" is not a word. Please use real words such as "please" when posting.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDBC is used to make a connection to the database and to retreive data from the tables. But you need a place to store the data that you retreive from the tables. This is where java beans are used. The data retreived from the tables are stored in JavaBean. And these JavaBean objects are passed between the servlets and the jsp according to the business logic.
 
Bear Bibeault
Sheriff
Posts: 67750
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
Though their use is not limited to data obtained via JDBC.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by suseela surendra:
we are able to connect to the database by using jdbc in jsp and servlets. Then what is the necessity of javabeans in jsp and servlets for getting date from the database?....



You don't need them.
It's entirely possible to write an entire web application using only servlets.
Doing so, however, would be very time consuming, tiring, and would result in code that is very difficult to debug and maintain. By breaking your app up into smaller, more specialized components, you make it easier to re-use code, and your code becomes cleaner and easier to read.
Servlets are great for handling web flow. JSPs are better for formatting the output. By moving your database operations out of the servlets, into Javabeans or plain old Java objects, you make them easier to test, debug, maintain, and reuse.

Personally, I like to be able to test all of my database components from the command line before trying to incorporate them into a servlet app.
This speeds up development but is even more valuable later on when trying to debug something that is not working as expected.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the use of java bean is that it manages the data that can be large enough. Which can't be retrieved directly. And also it is used to pop up the values. You can think it of a bag in which we are storing values and later taking them out.
 
author and cow tipper
Posts: 5009
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
The idea of a JavaBean is that it is reusable, it is testable, and it conforms to a variety of naming conventions and standards. Furthermore, it should be serializable - you must be able to pour milk over it and have it for breakfast.

A question was just asked in the JSP forum about "how do you debug JSP files?" The answer? Not easily. But if your code is in a JavaBean, testing becomes easier. Plus, how do you reuse code in a JSP? Basically, you can't.

For JDBC, I might suggest going beyond just a JavaBean, and factoring out an entire database layer. MVC-D is important. With so many different and emerging data models,(EJB 2.0, EJB 3.0, Hibernate, JDO, JDBC, etc) being able to plug and play your data tier is essential if you want a maintainable and flexible solution.

You don't have to use JavaBeans. There are no Java cops out there. But then again, fear of prosecution should never be the most compelling reason to do the right thing. Using JavaBeans is the right thing to do!

-Cameron McKenzie
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Plus, how do you reuse code in a JSP? Basically, you can't.



With include directive?
 
Bear Bibeault
Sheriff
Posts: 67750
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 Cristiano Sganzerla:


With include directive?



That's a really poor and hard-to-manage technique for code reuse.
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it demonstrates the visual construction of applications using component assembly mechanisms.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This would definitely help.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beans are nothing but java data carrier.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To reply to the question,with JavaBeans you can handle transaction,security and workflow features better as with servlets.
[ January 05, 2007: Message edited by: ismail ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Plus, how do you reuse code in a JSP? Basically, you can't.


The best way to reuse code in JSP is by creating and using Tag Libraries.
 
Bear Bibeault
Sheriff
Posts: 67750
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
"ismail",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Sheriff
Posts: 67750
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 Robert Berg:

The best way to reuse code in JSP is by creating and using Tag Libraries.



That's a really broad statement. Custom actions are one way (and a very powerful one) for creating re-usable code, but it's not always the best way.
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic