File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes With EJB why use Servlets. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "With EJB why use Servlets." Watch "With EJB why use Servlets." New topic

With EJB why use Servlets.

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 595
I have seen models of multi tiered Applications which use both servlets and EJBs. The way I see it, JSP represents the view, and servlets used to represent the business logic and link to the resources. With EJBs managing the business logic and EJB containers managing the resources, do we need the servlets.
Cheers for any help.
Leena Diwan
Ranch Hand

Joined: Jun 18, 2001
Posts: 351
many systems use JSP-Servlet_Appserver combination so it is quite obvious to get confused
For a even more modular system, we can have a JSP-Servlet-EJB-AppServer architecture.
Servlets act as pure extensions of the web server.. handle the requests, delegates calls to EJBs , "locating" them and then proceeding.
EJBs contain all the pure business logic.
Does it help ?
Thanks for your cheers !

chanoch wiggers
Ranch Hand

Joined: May 24, 2001
Posts: 245
I guess then you have to take a more finely defined understanding of business logic - Servlets are more performant than EJBs as well as lighter weight. Your servlets could include the application logic, while the EJBs would then become pure business logic, so, for a poor example perhaps:
JSPs show you balance
Servlets allow you to apply for an overdraft
EJB decides whether you can have one
JSP shows the result of the request.
I am not sure how sound an idea it is to be using EJBs from inside a JSP...

chanoch<p><a href="" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
For a more detailed explanation of typical web application architectures, check out this chapter from Professional Java Servlets 2.3 to see where Servlets, JSPs and EJBs fit into the picture.
Hope that helps
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 595
Thank you for the helpful replies, I will read up on that chapter.
Cheers Tony
I agree. Here's the link:
subject: With EJB why use Servlets.
It's not a secret anymore!