1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.geronimo.samples.bank.web;
19
20 import java.io.IOException;
21 import java.util.List;
22
23 import javax.ejb.EJB;
24 import javax.naming.Context;
25 import javax.naming.InitialContext;
26 import javax.naming.NamingException;
27 import javax.servlet.ServletException;
28 import javax.servlet.http.HttpServlet;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal;
33 import org.apache.geronimo.samples.bank.ejb.Customer;
34 import org.apache.geronimo.samples.bank.ejb.Account;
35
36
37 public class CustomerServiceServlet extends HttpServlet {
38 @EJB
39 private BankManagerFacadeLocal bm = null;
40
41 protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
42 viewCustomerInfo(req, res);
43 }
44
45 protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
46 doGet(req,res);
47 }
48
49 private void viewCustomerInfo(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
50 String path = "/error.jsp";;
51 try {
52 String customerCode = req.getParameter("customerCode");
53
54 List<Account> accountList = (List<Account>)bm.getAccountInformation(customerCode);
55 Customer customer = bm.getCustomer(customerCode);
56
57
58 if(accountList != null && customer!= null){
59
60 req.setAttribute("accountList",accountList);
61 req.setAttribute("customerCode",customerCode);
62 req.setAttribute("customerName",customer.getName());
63 path = "/customer_info.jsp";
64
65 }
66
67 } catch (Exception e) {
68 e.printStackTrace();
69 }
70 getServletContext().getRequestDispatcher(path).forward(req,res);
71 }
72
73 }