Suresh Kumar Nittala wrote:

> Hi,
>
> Kindly help me out.
>
> 1. How would you differntiate?
>
> A) Java Bean
> B) Enterprise Java Bean
> C) Servelets
>
> 2. Can we call Servelts directly from JSP?
>
> Regards,
> Suresh Kumar

EJB's are more like Servlets than JavaBeans.  JavaBeans are simply Java classes
that adhere to a handful of not-too-difficult conventions.  There exists advanced
support for JavaBeans beyond these simple conventions, but in the *vast* majority
of cases, understanding or even knowing about this advanced support is not
necessary.

EJB's and Servlets:
1) Both live inside a third-party 'container' which provides runtime support.  In
the case of Servlets, this is a web-server add-on.  In the case of EJB's this is
an EJB (application) server.
2) Like applets, neither Servlets nor EJB's use main() as their entry point.  They
have other pre-defined entry points.  For Servlets, doGet() and doPost() are
common entry points.  For EJB's, I'm on thinner ice.  I think, for example, there
are createXXXX() methods for constructing EJB's with different parameters.   EJB's
can also support arbitrary entry points (methods) to support arbitrary business
logic whereas Servlets cannot.
3) Servlets generally use HTTP as the client-server protocol, which is stateless,
and therefore requires special attention to session management.  EJB's use RMI
which is a much richer protocol.  EJB clients can call arbitrary (supported)
methods on a specific server-side EJB.
4) There is typically only a single instance of a Servlet on the server side
(although this can vary according to implementation).  Many clients (connections)
are supported by this single instance via multithreading.  Servlets must therefore
usually be coded in a thread-safe manner.  There are two types of EJB's:  Session
EJB's and Entity EJB's.  There is typically one Session EJB per client.  Thread
safety is therefore much less of an issue.  Entity EJB's are usually shared by
many clients because they usually correspond to a specific (persistent) record in
a database.
5) Finally, Servlets usually generate 'browser content' (all though, if you have a
non-browser client, such as an applet, you can generate arbitrary content).  Since
EJB's use RMI, arbitrary business-logic-support functions can be coded without
having to deal with the constraints of HTTP.

EJB's also have more 'enterprise' support, such as transaction management, whereas
by comparison, Servlets are 'bare bones'.

To answer your second question:  Yes, servlets can be 'called' from JSP pages
either by either 'including' the contents generated by the Servlet into the
JPS page, or 'forwarding' the JSP request to the Servlet so that the Servlet
generates the content instead of the JSP page.

If you want to make a method call from a JSP page, you would typically implement a
JavaBean with the desired methods which can be called directly, rather then
'calling' a Servlet.

cc

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to