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?
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.
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.
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.
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.
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!
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 ]
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.