javabean vs servlet [duplicate]
Asked Answered
S

5

25

I was searching for difference between javabean and servlet. I found

Servlet corresponds a Controller
JavaBean corresponds a Model

and

java bean is a reusable component,where as the servlet is the java program which extends the server capability

Now, what does re-usable means in javabean. Can't we re-use servlet ?

I will appreciate, if anyone can explain this, with few examples.

Suburbanize answered 6/12, 2012 at 15:30 Comment(2)
The difference is that they are not the same in an month of Sundays. Not a real question.Arce
@EJP that's why i'm asking what is the difference. If they are not same, then i believe, i would be much easy to explain, how they are differ. ??Suburbanize
P
31

Servlets and JavaBeans are completely different concepts. The servlet API provides for servicing Internet requests, typically from client browsers but not limited to that. JavaBeans are a component architecture for encapsulating functionality. A typical use would be a bean used by a servlet to handle database inquiries, but bean architecture is used in lots of places.

Sessions are the servlet mechanism for storing objects related to a particular user, these objects may or may not be beans. Beans used to create user interfaces (with your clever IDE) have more stringent requirements. Beans used in servlets and JSP are typically simpler.

Making it more straight, JavaBeans are to Java what ActiveX controls are to Microsoft. Javabeans can run on server side, client side, within an applet etc.

So, both have nothing in common except Java.

Panchito answered 8/12, 2012 at 18:0 Comment(0)
K
19

JavaBeans and Servlet are both concepts part of the Java EE (Java Enterprise Edition) package release in 1999/2000.

The servlet is a Java class (used as an Controller) in a java Web Application. Its role is to manage the HTTP Request and generate an HTTP Response. The Servlet is using JavaBeans to get its information from the database for instance.

The JavaBean is a simple java class used to represent the model of your application. To be called a JavaBean, the class must have public getters and setters for all its properties, must have a no-argument constructor, and must be serializable.

It is interesting to understand that this simple JavaBean concept migrates to the Enterprise Java Bean (EJB) in early 2000. But experience proved that EJBs were quite complicated to managed in the Java EE environment. Consequently, Enterprise JavaBeans were mostly replaced by "Pojos" (Plain Old Java Object) popularized by IOC Containers (like Spring in 2003). IOC pulled back Javabean to its former concept. IOC replaced the overall EJB-J2EE Templating pattern, Service Locator, Business Delegate patterns to a simple Injection of Dependencies (DI).

Kalliekallista answered 6/12, 2012 at 21:11 Comment(0)
I
8

They are two completely different things.

A servlet is used for handling requests in a web application, so yes it is similar to a controller.

A Java bean is any java class that adheres to a set of rules, see: What is a "Java Bean"?

I guess whatever you are reading is telling you how each fit into the MVC pattern

Illconditioned answered 6/12, 2012 at 15:39 Comment(2)
you mean, both are different things ?? So, can you elaborate both terms ? I mean what are they and where do we need them ?Suburbanize
JavaBean - Read the link in the questions, servlet, read this: docs.oracle.com/javaee/5/tutorial/doc/bnafe.html but essentially a servlet is used to handle HTTP requests in a web application.Illconditioned
B
1
  • The Life cycle of Servlet manage by Web container where In case of Java Bean you are initialize or initiate your java Bean.

  • There are two type of servlet, Generic Servlet which support different type of protocol request where HTTPServlet which support HTTP protocol.

  • In most of the framework like struts/Spring, they use servlet as controller to take the request call and depends on the configuration, it's divert the call to different Action Class/Action Controller

Blayne answered 12/12, 2012 at 8:59 Comment(0)
A
0

Java bean is a data access object which is used to interact with the database.Java bean is a POJO (Plain Old Java Object).A servlet is used with the JSP, like an interface for JSP. Both java bean and Servlet are part of the MVC.

Alpestrine answered 4/5, 2016 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.