Java Session Bean

April 30, 2012    blog jsp session beans school

Lab Question:

A company has asked you to develop a mortgage payment calculator web site. This application which is created using Enterprise Java Beans, takes some parameters such as interest rate, mortgage amount and the interest term from the user and calculates the mortgage monthly payments. The result is back to the client. All of the business logics are implemented using Enterprise Java Bean.

In more details, your application has the following components:

– Client tier which is a servlet or jsp

In client tier, you take the following parameters from the user:

– Enterprise tier: in this tier, you implement a session bean and its required interfaces.

For this lab, only implement the following parts:

– Implement a Session Bean. Decide whether it should be stateless or stateful. Explain the reason.

– Implement the required interface and the business methods.

 

Problem:

The remote method and class for the session bean is not automatically created in the newer version of Java.

Impact:

The method that calculates the monthly mortgage payments will not work because there is no remote method.

Solution:

Manually create the remote class and implement the method inside of the class.

import javax.ejb.Remote;

@Remote
public interface SayHelloRemote {
Double HelloMethod(double amount, double rate, int year, int month);
}

Then call the method inside of the java server page.

Context ctx = new InitialContext();
SayHelloRemote sb = (SayHelloRemote) ctx.lookup(SayHelloRemote.class.getName());

Double payment = sb.HelloMethod(amount, rate, term, monthterm);