Working with Session Beans B Ramamurthy 132022 B
Working with Session Beans B. Ramamurthy 1/3/2022 B. Ramamurthy 1
Introduction We will session beans from two points of view: n n 1/3/2022 the session bean developer who implements a session bean the client application programmer who uses the session bean B. Ramamurthy 2
When to use session beans Session beans is used to implement a stateful communication between a client and a server. A session object lasts for the duration of the client’s session. The duration of a session is the time between the creation of the session bean and its removal. During this time, session bean stores the state information (conversational state) for the client. 1/3/2022 B. Ramamurthy 3
When to use. . (contd) Stateful session beans are suitable for the following situations: n To implement session logic of Web applications. One or more session beans can be used to implement the business process that drives the conversation with the user. w Example: Process that inputs billing and shipping information n To implement session logic of traditional non-Web based applications. Ex: Teller of a bank interacts with an application to enter multiple checks. 1/3/2022 B. Ramamurthy 4
Session Bean in Web Application Form generation Web Container Form Display Web Application client Business Logic EJB container Session Beans JSP, Servlets Database Server Html over http 1/3/2022 B. Ramamurthy 5
Stateful vs Stateless Session Bean Session bean can stateful or stateless An instance of stateful session bean is associated with one client. One to one correspondence between session objects and instances of session bean class. Stateful session bean implements a conversational business process. “state” provides a convenient way of retaining client-specific state on the server. 1/3/2022 B. Ramamurthy 6
Stateless Session Bean Does not retain any client specific data. Container has pool of instances of stateless session beans and client requests are delegated to any available beans. Reused by different clients. Typically implements a procedural service on top of a database or legacy application. Ex: Pay. Roll that simple gets db information to the user whose identity is given. 1/3/2022 B. Ramamurthy 7
Conversational State A stateful session bean keeps the server -side state on behalf of a single client. This may contain: n n 1/3/2022 Data read from the database Information entered by the user. B. Ramamurthy 8
Example Application: Benefits Enrollment Web application through which an employee manages his/her benefits selections. The application lets an employee enter, review, and change his/her selection of employer provided benefits. Three databases are involed: payroll, employee and benefits 1/3/2022 B. Ramamurthy 9
User View User points to an URL. Application displays a sequence of HTML pages containing the various benefit choices available to the employee. After employee choice it display next screen. It also summarizes the selection. It also indicates the previous selection. After confirmation from the user the application updates information. There is a intial login page and final confirmation page besides the one shown on page 62. 1/3/2022 B. Ramamurthy 10
Main Parts 1/3/2022 B. Ramamurthy 11
Benefits Enrollment Application Web Container Deploys : Enrollement. Web EJB Container 1 Deploys : Payroll. EJB Benefits App Server EJB Container 2 Deploys : Enrollment. EJB Enrollment App server 1/3/2022 B. Ramamurthy Database Server Deploys : Payroll. Database Server Deploys: Employee. Database Server Deploys : Benefits Database 12
- Slides: 12