Difference between Servlets and EJB:
1. Servlets Run on web container of the Web Application server
where as EJB runs on EJB Container either provided explicitly
(
JBoss, Blazix) which needs to be configured with a web server
, or the web application server (costly ones) comes with
integrated EJB containers (Sun
Java Application Server, Websphere,
BEAWeblLogic)
2.It is the EJB container which maintains EJB's peristence,
transactions and pools. But for Servlets there is no such thing
like this. To maintain session persistense using Servlets, the
programmer/developer has to take care of it usiing session
attributes and also has to keep an eye on
thread safety of the
servlets.
3.A servlet can service only web requests. Ofcourse it can also be
called from sockets (tedious programming and security hole) but
EJB's can be tied up to client server objects also through RMI-IIOP
/JNDI.
4. EJBs (Bean Managed Persistense & Container Managed Persistense,
I mean not session beans) has finder methods, Servlets do not
have such.
5. A CMP bean represents an entity at database level, not servlets.
I hope I am being able to answer these at a very theoritical level.
But honestly speaking these cannot be exemplified programatically. Coding
for servlet and EJB if you want to know - download SUN JDK J2EE and play
with the samples.
Regards,
Caesar