Search code examples
javaservletsjavabeansreusability

javabean vs servlet


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.


Solution

  • 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.