Listing 1: Key logic for login controller JSP (doLogin.jsp)
<%
String id = request.getParameter("username");
String password = request.getParameter("password");
Login loginCommand = new Login();
loginCommand.setCustomerLogin(id);
loginCommand.setCustomerPassword(password);
String urlString = JSPUtil.getBaseURL(request);
Listing 2: Business logic of Login command (Login.java)
try {
loginCommand =
(Login) CommandManager.execute(loginCommand);
HttpSession session = request.getSession(true);
session.putValue("customer",
loginCommand.getCustomer());
session.putValue("transactionList",
new Vector());
response.sendRedirect(urlString +
"viewBalance.jsp");
} catch (CommandException commandException) {
response.sendRedirect(urlString
+
"login.jsp?customerID=" +
id);
}
%>
try {
CustomerHome customerHome = (CustomerHome)
EntityUtility.lookupHome(CustomerHome.class);
Customer customer = null;
try {
customer =
customerHome.findByLogin(customerLogin);
} catch(ObjectNotFoundException ex) {
throw new InvalidLoginException();
}
if(!customerPW.equals(customer.getPassword())){
throw new InvalidPasswordException();
}
customerDataBean = customer.getDataBean();
} catch(Exception ex) {
ex.printStackTrace();
throw ex;
}
Listing 3: Excerpts from the Customer EJB (CustomerBean.java)
public void ejbCreate(String login,
String password,
String name)
throws RemoteException, CreateException
{
this.login = login;
this.password = password;
this.name = name;
}
Listing 4: Key logic for viewBalance.jsp
public CustomerDataBean getDataBean()
throws RemoteException
{
CustomerDataBean dataBean =
new CustomerDataBean(login,
password, name);
return dataBean;
}
<%
CustomerDataBean customerInfo =
(CustomerDataBean)
session.getValue("customer");
ViewAccounts viewAccts = new ViewAccounts();
viewAccts.setCustomerID(customerInfo.getID());
try {
viewAccts = (ViewAccounts)
CommandManager.execute(viewAccts);
Vector accounts = viewAccts.getAccounts();
%>
<!-- NOTE: HTML table setup code deleted -->
<%
for (int i = 0; i < accounts.size();
i ++) {
AccountDataBean
account =
(AccountDataBean)
accounts.elementAt(i);
double balance
= account.getBalance();
String formattedBalance
=
currencyFormat.format(balance,
new StringBuffer(),
fieldPosition).toString();
%>
<!-- some formating code
deleted -->
<TR>
<TD> <%= account.getDescription()
%></TD>
<TD> <%= formattedBalance
%></TD>
</TR>
<%
}
} catch (Throwable e) {
e.printStackTrace();
}
%>
Listing 5: The business logic of the ViewAccounts command (ViewAccounts.java)
try {
accounts = new Vector();
AccountHome accountHome = (AccountHome)
EntityUtility.lookupHome(AccountHome.class);
Enumeration accountEn =
accountHome.findAllAccountsForCustomer
(customerID);
while (accountEn.hasMoreElements())
{
Account account
=
(Account)
accountEn.nextElement();
accounts.addElement(account.getDataBean());
}
} catch(Exception ex) {
ex.printStackTrace();
throw ex;
}
Listing 6: Extracts from the Account EJB (AccountBean.java)
public void ejbCreate(double balance,
String description,
int customerID)
throws RemoteException, CreateException
{
this.canWriteChecks = false;
this.balance = balance;
this.description = description;
this.customerID = customerID;
}
public AccountDataBean getDataBean()
throws RemoteException
{
AccountDataBean dataBean =
new AccountDataBean(canWriteChecks,
balance,
description, customerID);
return dataBean;
}