Servlets Vs EJB

Hi,
I have to make a choice between going for Servlets or EJB in an on going enterprise project.The application is very speed sensitive,so definately servlets tend to be the preferred choise and it it true that in the present state EJB usage is not truly required.But in future different
transactions related modules will be added which will be only possible to add if we go for EJBs (as they are very complex).Hence the delimma is to use only servlets in the current application and add EJB modules as and when need arises or go for EJB design in the current scenario also for the modules which are not speed sensitive ? I have read that EJB usage,though, complicated can reduce down the design related problems for an Enterprise application.Kindly suggest a solution.

I'm not your pal.Hei i donot want to be your pal you stupid.Thank God for that. We agree on one thing.
But you still writing the transaction code whereas
you can manage applications transaction by simply
configuring in appication server.No, I'm not. Better go learn about Spring. It's got declarative transactions, exactly like EJBs. Configure Spring, configure app server - same thing.
Are You going to temper it by writing again. No.
If u conatainer managed transaction you do not have touch anything.If you have Spring-managed you only have to change configuration, just like EJB.
I know we can also write our applications
functionality without using EJB. but i said that in
n some circumstances i'd suggest that EJB is better.I'd suggest that it might not be.
Like -
1. Integration with the legacy SystemCan do it with Spring remoting.
2. Scalability requirement.App servers are still the way to go here. Clustering is still handled by container. But they don't have to be EJBs.
3. Security Managemant.Spring ACEGI provides declarative, role-based security.
4. Distributed Transaction Requirement.Can do this with XA drivers and JTA, without EJB.
5. Persistence Management.DAOs and Hibernate. Even EJB 3 is adopting it.
6. portability.No more or less portable than Java.
Are you saying you can pick up a WebLogic app and deploy it, without any changes, to JBOSS or any other Java EE app server? Not if you use custom extensions.
It'll depend on the application that we are developing. Yes.
I think, Its not about who knows what and how much,
its about gethering knowledge. That is why i am
logged in to this forum. We have to find out the
technology that is provided by SUN to us to solve our
problem with ease to its best potential.No arguments there.
%

Similar Messages

  • Web Services - Servlets vs EJBs

    Hi,
    Looking for any suggestions about the benefits of using either servlets or EJBs as web service endpoints. Very early in the design of any application, I wish to expose my business logic components as web services, is there any particular benefit to using a specific approach (i.e. using either EJBs or Servlets as the end points of the web services exposing the business logic)?
    This is a totally new application so I have no considerations towards reusing old EJB code, etc. My initial thoughts favour using servlets, if only because it reduces the complexity / resources required for the application server (i.e only Web-container required, rather than Web & EJB container).
    Any thoughts please?

    Why do Servlets not scale as well? Surely they are
    more "lightweight" than an EJB (which has all theRMI
    overhead), and wouldn't it ultimately be down tothe
    underlying app server anyway?Right, but servlets are just HTTP request listeners.
    They aren't components, they aren't transactional,
    they don't handle persistence, they don't have
    naming services, they don't have queuing services.
    The EJB container offers you a lot.
    With that said, it's not just a choice between
    servlets and EJBs. You can use POJOs and avoid EJBs
    altogether if you do it right.
    Or choose the best of both worlds and mix 'n match as needed.
    Noone forces you to choose one over the other (at least not for any technical reasons, I'm not diving into corporate politics here).
    My thought was that web services were a better wayto
    expose business logic than EJBs, but if there some
    solid reason why this isn't the case I like toknow.
    Web services - lightweight? Maybe that's true of
    REST, but certainly not SOAP. There's an argument
    that says services are more heavyweight than EJBs,
    because all the XML on the wire is an expensive
    protocol.
    SOAP is heavy on the network, but it's essentially a rather thin layer on top of other services (if properly architected).
    For example we have a SOAP layer exposing a Spring application which proxies an EJB architecture.
    Next to that SOAP layer sits a traditional web application (servlets) which itself has a Spring application sitting on top of it for demonstration and testing purposes.
    And then there's an SDK allowing direct access to the Spring layer (and thus almost direct access to the EJB layer).
    That's the beauty of a true open architecture, each component can be built on top of another and the component underneath can function just fine without it.
    Look into Spring:
    http://www.springframework.org
    It's a lighter alternative to EJBs, and good plumbing
    for any Java EE app.While Spring can serve as an alternative for EJB in places where EJB are overkill it's of course not in competition with it.
    Spring is a service layer, making use of other technologies (like EJB, like AOP, like ORM) to provide data and other services (like Struts, like JSF, like JSP) to provide that data to requesters.

  • Servlet and EJB on different machine: Security propagation

    Hi all,
    I have an application, where my servlets and EJBS are deployed on the same machine.So
    when in my servlet a user need to authenticate himself, security credentials are
    propagated to the EJB automatically.I'd like to know in the case where the components
    are on different machine if I need to put the credential in my InitialContext
    when my servlet calls my EJB or if it is also done automatically.
    Cheers
    romain

    Say your stub is in a jar called stub.jar.
    You need to put that stub somewhere that it can be reached through a protocol for which Java has a URL type - so you can put it on a shared file system and use a file URL or behind an http server and use an http URL.
    Let's use http - put stub.jar at the docroot of a web server.
    Then, when you start your SERVER code, include this VM parameter:
    -Djava.rmi.server.codebase="http://<serveraddress>stub.jar"
    Now your client will be able to use http to load the stub file out of stub.jar through http.
    If you do use a file URL, make sure the shared directory you put your jar in is not on the client's classpath.

  • Thred Safety when Injecting an EJB into servlet using @EJB

    Hi , i have read that
    when EJBs were injected into servlets using @EJB it is said that there will be no Thread Safety here ??
    Is this true.

    Hi,
    You can directly call the methods in the bean without using bean model
    see this thread
    Webdynpro and Oracle
    Regards
    Rohit

  • Good books for learning Java(Servlets,JSP,EJB,etc.,),Javascript.

    Hi Experts,
    Can you suggest me some good books on java , javascript.The books should include the internals of Servlets,JSP,EJB.
    Thanks
    vishal

    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=756427&start=7
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=751055
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=743429
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=742997&start=11
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=750775&start=24
    Just a simple search for this forum....
    It took me 10 seconds tofind these..
    JJ

  • When to Use Servlet only, EJB only and, both Servlet And EJB???

    I have a question, If I want to build a Web application. Sometime i found that there is no need to use EJB as Servlet already provide that functionality.
    Can anyone tell me when do I use Pure Servlet? When do I use Pure EJB and, When do I use Both EJB and Servlet???
    I am very interesting in it.
    Thanks.
    Jack

    EJB and servlets are two different things. Trying to compare them doesn't really make sense. A web application is always going to need some way to process Http requests and this in Java is done accomplished through Servlets (or jsp pages which in turn also use servlets).
    EJBs are the basis of distributed cross-platform objects. They are handled through name services and stored in databases. An Entity Bean can be "brought back to life" as long as it's info is stored in a database. Regardless of a server being restarted. All this database support behind an Entity Bean (transactions, queries etc.) are very transparent to the programmer. They are provided by the EJB vendor.
    The class properties of a Servlet (or class-level member variables) are shared among all requests (running thread instances of the service method). That's why they should be used with a lot of caution. This feature can be very useful but if used improperly can also be very vulnerable to security and synchronization issues.
    I'm not an EJB expert but this explanation should give you some idea of what EJBs are all about.

  • How to pass submitted Data from a servlet to EJB Session Bean in JPA

    How to pass Data User submitted Data from a servlet to EJB Session Bean when using JPA :
    Hi ,
    I have a jsp page in which the user fills up the Data and submits it to the servlet :
    Inside servlets i am getting all the parameters and setting it to the Entity Class .
    Sample Entity class is shown below :
    @Entity
    public class Employee {
    @Id private int id;
    private String name;
    public Employee() {}
    public Employee(int id) { this.id = id; }
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    }After calling setters of my Entity Class .
    I am using JNDI lookup to call my session Bean method and pass this Entity class to the session Bean to persist data
    Please let me know what will be the right approach :
    1. Passing parameters whole as a Entity Class
    that is
    public void insertData(Employee emp)
    }Or
    2. public void insertData(String Name , int ID)
    }

    they are both right as they both work. Easy huh?
    You might argue that if you have to set a lot of fields, use the entity as otherwise you get a method with a gigantic amount of parameters.

  • Desgin issue, Servlets with EJBs in real life?

    When designing a web application with WLS and has anyone made extensive use
    of EJBs with Servlets/JSP.
    Servlets and JSPs are pretty much a must for the web-app, but are EJBs
    really so?. Correct me if I am wrong, the reason that we would wanna use
    EJBs (especially I am talking about session EJBs), within servlets
    is the fact that they are transactional (so you don't implement transaction
    logic in your code), or their being clusterable, thus higher availability by
    failovers, etc, ,
    They are not faster than standard Java, actually.
    by using EJBs in our design we're not gonna gain that much of a speed and
    our development time is gonna be longer (well, if designed well, EJBs might
    be good candidates for reusability),
    instead they are gonna give us higher reliability and availability, along
    with a cost of rather slower
    responses.
    I'll post an explanation of the simle load tests that I have done on the WLS
    with two different architectures,
    namely Servlet + Std. Java & Servlet + Stateless EJB, shortly
    Any comments appreciated,
    thanks,
    ali.

    EJBs are a tool in your arsenal. Just like Servlets -- you don't hear
    developers suggesting that you avoid Servlets/JSPs and just handle port 80
    directly in your own code!
    Yes, they are transactional objects for Java. Half the time they are a pain
    in the a** but they are better than everyone making up their own standard.
    They are not faster than standard Java, actually.They are standard Java, so they are not faster. Since the container either
    gens code or uses reflection or both to run them, they are typically a bit
    slower than doing direct JDBC (for example) in your servlets. Also, it is
    easy to get very bad performance if you don't realize how many database
    operations a set of ejb invokes can be.
    All in all, once you know EJBs you will probably want to use them, because
    they get the job done and are pretty efficient when built correctly. Until
    then, they will seem like a pain, largely because they are ;-)
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com
    +1.617.623.5782
    WebLogic Consulting Available
    "ali" <[email protected]> wrote in message
    news:[email protected]...
    When designing a web application with WLS and has anyone made extensiveuse
    of EJBs with Servlets/JSP.
    Servlets and JSPs are pretty much a must for the web-app, but are EJBs
    really so?. Correct me if I am wrong, the reason that we would wanna use
    EJBs (especially I am talking about session EJBs), within servlets
    is the fact that they are transactional (so you don't implementtransaction
    logic in your code), or their being clusterable, thus higher availabilityby
    failovers, etc, ,
    They are not faster than standard Java, actually.
    by using EJBs in our design we're not gonna gain that much of a speed and
    our development time is gonna be longer (well, if designed well, EJBsmight
    be good candidates for reusability),
    instead they are gonna give us higher reliability and availability, along
    with a cost of rather slower
    responses.
    I'll post an explanation of the simle load tests that I have done on theWLS
    with two different architectures,
    namely Servlet + Std. Java & Servlet + Stateless EJB, shortly
    Any comments appreciated,
    thanks,
    ali.

  • Servlet to EJB in WAS 6

    Hi,
    I am new to EJBs. can any one direct me the way to provide a communication from Servlet to EJb using WAS 6. I am using the IDE, RAD.
    Thanks in advance

    Shawn,
    You mmay have 2 separate problems. To find out which rmi port to make it static you can do the following:
    You can find out which rmi port is being used by doing
    $ORACLE_HOME/opmn/bin/opmnadmin debug comp=pm
    In Oracle9iAS environment the ports are dynamically assigned and you have to fix a specific port for RMI by specifying a range for your OC4J
    instance in Enterprise Manager :
    (Server Properties -> RMI ports -> 3101-3101 where EJBs are deployed
    To fix the domain was null error you must
    populate the environment entries for the lookup from the remote web application.
    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.rmi.RMIInitialContextFactory");
    env.put(Context.SECURITY_PRINCIPAL, "admin");
    env.put(Context.SECURITY_CREDENTIALS, "pass");
    env.put(Context.PROVIDER_URL, "ormi://hostname:3101/ejbsamples");
    env.put("dedicated.rmicontext","true"); //works in 9.0.3 and 9.0.2.1
    env.put("dedicated.connection","true"); //works 9.0.2.
    -Prasad

  • Servlets and EJBs

    Hi,
    My question, is possible to access from servlet some EJB through EJB's local interface, even these participate two different containers?
    Regards
    Krzysztof

    I am not that good with EJB , but I donot think so
    EJB Local interfaces only work from othe EJB's AFAIK,

  • Servlet + Local EJBS

    Hi,
    I'm about to deploy the Servlet using the Local EJB interfaces. The problem
    I've encountered is that when I try access the local home interface I get
    the ClassCastException. But object returned does indeed implement the local
    home interface. I suppose, there are some repeated classes both in ejb and
    web deployments. Can someone tell me how to make my servlet access the same
    classes as deployed local ejbs?
    Thanks in advance,
    Andrzej

    Ok, that's the reason.
    Thanks.
    You can only access local EJBs within the application. Are you deployingthe
    servlet and ejb together in an ear file?
    -- Rob
    Andrzej Dmoch wrote:
    Hi,
    I'm about to deploy the Servlet using the Local EJB interfaces. The
    problem
    I've encountered is that when I try access the local home interface Iget
    the ClassCastException. But object returned does indeed implement thelocal
    home interface. I suppose, there are some repeated classes both in ejband
    web deployments. Can someone tell me how to make my servlet access thesame
    classes as deployed local ejbs?
    Thanks in advance,
    Andrzej

  • Servlet, JSP, EJB

    Hi!
    I have some general questions about jsp and servlets. I develop an internetbased portfoliosystem which uses ejb to extract data from an oracle database.
    q1: How can I create a controlling servlet for page direction?
    q2: How can my jsp file connect to my ejb (session bean)? Can I do it directly or must I go through an AccessBean? (if accessbean, how do I do that?)
    Sincirely,
    Nicolai
    Answers/examples may also be sent to: [email protected]

    1 For a controller servlet you can use a servlet controller model, ie the presentation logic is in the JSP pages , which submits request to the servlet which does appropriate processing and then redirects the flow to another JSP.
    2. Your JSP file can connect to EJBs directly through the remote handle of the bean obtained by JNDI lookups. However the JSP gets cluttered with the JNDI lookup codes.If the HTML programmer is different from Java programmer then go for accessor beans.

  • Servlets and EJBs in weblogic 5.1

              Me somebody can say like communicating servlet that this in a machine with Weblogic 5,1 with a EJB in another machine also with weblogic5.1
              When trying gives it to me Comunication Exception .
              But if I have the 2 in the same machine it works well
              

    We have the same scenario and had the same CommunicationException.
              We had the remote & home interfaces of the ejb and the helper classes
              avaliable
              to the server#1 , and still encountered the following CommunicationException
              Tue Feb 06 17:53:54 GMT+05:30 2001:<I> <ServletContext-General>
              scripInfoServletWAP25:
              ScripInfoServlet.init()javax.naming.CommunicationException [Root exception
              is weblogic.rmi.UnmarshalException: Unmarshalling return
               - with nested exception:
              [java.lang.ClassNotFoundException: class
              ITS.beans.order.ScripInfoSessionEJBHomeImpl_ServiceStub previously not
              found]]
              Tue Feb 06 17:53:54 GMT+05:30 2001:<E> <ServletContext-General> Servlet
              failed with Exception
              javax.servlet.ServletException: javax.naming.CommunicationException [Root
              exception is weblogic.rmi.UnmarshalException: Unmarshalling return
              - with nested exception:
              [java.lang.ClassNotFoundException: class
              ITS.beans.order.ScripInfoSessionEJBHomeImpl_ServiceStub previously not
              found]]
              at ITS.wap.ScripInfoServletWAP25.init(ScripInfoServletWAP25.java:83)
              at
              weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java
              :390)
              at
              weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.ja
              va, Compiled Code)
              at
              weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.jav
              a:338)
              at
              weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:16
              4)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :99)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:742)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:686)
              at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              Manager.java:247)
              at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
              at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code)
              Only when the jar file was made available to the server#1(i.e. present in
              weblogicclasspath but not deployed) was the servlet on server#1 able to call
              the ejb on server#2.
              When calling the ejb through a Java Application or through a servlet
              deployed on the same server as the ejb,
              the stub classes are not required to be specified in the weblogicclasspath.
              Has anybody else encountered a similar situation?
              Thanks in advance.
              Aparna
              "Cameron Purdy" <[email protected]> wrote in message
              news:[email protected]...
              > You can have a Servlet on server #1 talk to an EJB on server #2. It is
              > accomplished by having the client classes for the EJB available to the
              > Servlet on server #1 and using JNDI on server #1 to get initial context
              for
              > server #2 and using that to look up the EJB.
              >
              > (Sorry, no habla espanol.)
              >
              > --
              > Cameron Purdy
              > Tangosol, Inc.
              > http://www.tangosol.com
              > +1.617.623.5782
              > WebLogic Consulting Available
              >
              >
              > "Javier Fdez" <[email protected]> wrote in message
              > news:[email protected]...
              > >
              > > Me somebody can say like communicating servlet that this in a machine
              with
              > Weblogic 5,1 with a EJB in another machine also with weblogic5.1
              > > When trying gives it to me Comunication Exception .
              > > But if I have the 2 in the same machine it works well
              >
              >
              

  • Separate jsp/servlets from EJBs for petstore

    By default, petstore deploy all the web apps and EJBs in one ear. I am trying to
    separate the JSP/servlets to deploy to diffent machine. I need to modify the client
    InitialContext to point to the remote server. I took a look at the source and
    there are many places using the default constructor of InitialContext to load
    the default URL. I wrote a jndi.properties file that has the correct url and put
    this to the classpath. I know this file needs to be put to the working directory,
    too. In case of pet store web application, what should be the working directory?
    Thanks, Cathy

    I'm also interested in running the Pet Store application server and the database
    (Oracle prefered) on different systems.
    Is this configurable during runtime or does it require code modification, compilation
    and deployment?
    Thanks,
    TL

  • NON-SERVLET, NON-EJB DYNAMIC CLASS RELOAD

    hi,
              In weblogic 5.1, is there a way to reload a class from the clientclasses directory without restarting the server? it's just a class in the clientclasses used by the JSPs. a kind of hotdeploy for NON-EJB, NON-SERVLET CLASS. SPECIFIC guidance will be immensely appreciated..
              Thanks in advance
              Vijay
              

    please show us the full error message.
    it sounds like a classpath problem...

Maybe you are looking for