Using Servlets, JSP, and EJB

An application based on EJB is today commonly viewed as the Holy Grail. However, it’s also the most complex model of the ones described in this chapter, and it therefore comes with overhead in the development, deployment, operation, and administration areas. While EJB may be the way to go for some types of applications, it’s overkill for many others. Think long and hard about if you really need EJB, or if you’re just influenced by all the hype around it, before you decide to go this route.

What EJB brings to the table is primarily transaction management and a client type-independent component model. Even though it’s impossible to say with certainty that a specific type of application should definitely use EJB, if you develop an application with numerous database write-access operations accessed through different types of clients (such as browser, standalone application, PDA, or another server in a B2B application), EJB is probably the way to go. An EJB-based application also enforces the separation between the Model, View, and Controller aspects, leading to an application that’s easy to extend and maintain.

There are two primary types of EJB components: entity beans and session beans. An entity bean represents a specific piece of business data, such as an employee or a customer. Each entity bean has a unique identity, and all clients that need access to the entity represented by the bean use the same bean instance. Session beans, on the other hand, ...

Get JavaServer Pages, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.