How to call stateless session bean from a servlet or JSP

Discussions

Web tier: servlets, JSP, Web frameworks: How to call stateless session bean from a servlet or JSP

  1. First of all tell me when to use EJB and when to use only Jsps and sevlets??
    Can anyone help me out on this???
    How can I call thestateless session from a jsp and how do I transfer the parameters from jsp/servlet to Session bean???
    plz help
  2. To answer your first question ... if you've ever heard of the MVC (Model-view-controller) pattern or n-tier pattern of development, then the JSP/Servlets are the 'View' part of it - or the 'Presentation' layer in the n-tier system. Meaning, they are primarily responsible just for displaying the data & accepting input. To some extent JSP/Servlets can be 'Controllers', i.e. they can control/define the flow of an application.

    However, it is bad design to put your 'Model' part (i.e. the 'business logic' part) in JSP/Servlets. That is what you use the EJBs for. EJBs (Session/Entity/Message) should ideally be used to handle the business rules part of your app. This allows your app to easy to maintain when there are changes & also provides you with all benefits of the J2EE architecture - i.e. scalability, security, pooling, transactions, distribution, messaging & naming.

    My advice ? Try to put display logic in JSP/Servlets & put your business logic in EJBs - easy as pie.

    Sameer.
  3. Here are links for first question...

    http://www.theserverside.com/resources/article.jsp?l=Is-EJB-Appropriate

    http://www.cs.unc.edu/Courses/comp119/docs/lessons-others/ejb-brown-02/EJBArchitectures.pdf

    This will help you deciding When to use EJBs...

    Raj
  4. You can have a look at this link for calling Stateless Session bean from either JSP or Servlet
  5. Sorry Here is the link

    http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/DEA2eTOC.html