Juraj Kazda wrote:
> Hi friends,
>
> I still don't have clear in this questions:
>
> When it is better to use EJB than servlets or JSP?
> What are EJB from view of servlets?
>
EJBs serve a different purpose from servlets and JSPs -- it is often
appropriate to use both. From the point of view of a servlet or JSP, I view an
EJB as an encapsulated piece of business logic (session beans) or data (entity
beans).
I find that session EJBs are particularly useful for encapsulating business
logic that is transactional -- in other words, if something fails half way
through, you want to be able to roll back your changes. Entity EJBs are quite
useful for representing data in a database, where the EJB server manages the
data caching and sharing problems for you (which can be really significant).
The simplest thing to remember, though, is that EJBs have no "user interface"
that a human can see. That's where servlets and JSP pages come in.
>
> There is model written down in J2EE, where user calls JSP or servlet,
> JSP/servlet calls EJB, EJB returns results to JSP/servlet and then output is
> generated back to user. For what situations is this good way? Isn't it
> enough to do all backend operation just in JSP/servlet? Should I use EJBs?
>
I use a model like this for nearly all of my servlet/JSP applications, even
when EJBs are overkill for my data handling requirements. An EJB can be
treated a lot like a bean in a JSP page (referring to it in a <jsp:useBean>
action, for example) in a scenario like this:
* User fills out an input form
* Form submitted to a servlet
* Servlet looks up the processing
required to perform this request,
which could easily be a session EJB.
* Called request processing can
create some results (for example,
returning references to entity EJBs)
that are stored in the user's session
* Servlet forwards control to an appropriate
JSP page to display the results using
RequestDispatcher.forward().
* JSP page uses the results with
<jsp:useBean>. The concession you
have to make to their EJB-ness is to
deal with the possibility of a
RemoteException, but you can do that
fairly easily with a big try-catch block.
The "Application Programming Model" documentation on JavaSoft's web
site (http://java.sun.com/j2ee) does a pretty good job at describing which
technologies to use where.
>
> Thank you for help.
>
> --jerry
>
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html