Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why we need javabeans?

 
suseela surendra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.....
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Bear edit: uncited copy removed.]
[ December 28, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suseela surendra,

"Pls" is not a word. Please use real words such as "please" when posting.
 
Anu Pillai
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Though their use is not limited to data obtained via JDBC.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Vivek tcs
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
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
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
 
Cristiano Sganzerla
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plus, how do you reuse code in a JSP? Basically, you can't.


With include directive?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it demonstrates the visual construction of applications using component assembly mechanisms.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would definitely help.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beans are nothing but java data carrier.
 
ismail hassani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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 ]
 
Robert Berg
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64837
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic