HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"The Java 2 Enterprise Edition and e-Business"
Volume: 4 Issue: 12, p.66

	

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; 
} 
  
  
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.