• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB versus servlet

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers
I am totally new to EJB and I want to know the difference between EJB and servlet.
When is the use of EJB over servlet recommended or viceversa.
Or can they be compared anyway.
thanks in advance.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They can't be compared as they do completely things.

A servlet processes requests from web pages. And EJB processes requests from other sources - such as servlets, remote calls or queues.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

If you have read about MVC(Model View Controller) if not do read it. it will be good for understanding this..

Here Servlet is your controller that takes care of your request and response processing..
Your controller calls the model for business logic processing. and posts the reponse back to the client.

Model can be your EJB, or a webservice, or a plane java call.
So EJBs are used as model in distributed systems (where your different components stay on different machines).. like your servlet can on one server and ejb can be deployed on different server.

And view is your display can be a jsp or plane html..


 
tehika danait
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Sushil and Jeanne
Sushil's explanation was good and i am know getting the idea, but one more question:
Why and when do we use EJB rather than plain java?
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tehika wrote:Why and when do we use EJB rather than plain java?



Container provide various services for us like transaction, security etc. so we don't have to write code for all such services so we can concentrate on business methods of of our interest.
EJB is reusable component so we can use it over any EJB container provider.
 
tehika danait
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If we use MVC methodology, the plain java code is separate from the model and view, so why is security an issue?
 
tehika danait
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, I mean the controller and view
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Security is always an issue, and it deeply affects all layers of a system, no matter how it's architected. A JEE server provides authentication and authorization features for EJBs.
 
sushil grover
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As described above by Ulf Dittmer, Security is the issue because you should be able to restrict the client who is calling your Business logic(EJB). For this container provide these services to authenticate the clients. In EJB's security can be handled declaratively(defining roles and all in different xmls files of container) as well as programmatically as per EJB API for security.

Container provide other features also like life cycle management(managing how many instances are there for ejb at a time).

You can read this article if you really want to go little deep into this. Although EJB is very huge topic.

http://java.sun.com/developer/onlineTraining/EJBIntro/EJBIntro.html
 
Wink, wink, nudge, nudge, say no more, it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic