This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB versus servlet  RSS feed

 
tehika danait
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
sushil grover
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
sorry, I mean the controller and view
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!