addinvestor.jsp
01 <%page contentType="text/html; charset=Shift_JIS" %>
02 <%page import="javax.naming.*,
03                  java.text.*,
04                  java.util.*,
05                  trail.entity.beans.*,
06                  trail.entity.basic.*"%>
07 
08 <%!
09   private Calculator cal = null;
10   private NumberFormat nf = null;
11 
12   public void jspInit () {
13     try {
14       InitialContext ctx = new InitialContext();
15       cal = (Calculatorctx.lookup(
16                   "EJB3Trail/EntityCalculator/local");
17     catch (Exception e) {
18       e.printStackTrace ();
19     }
20 
21     nf = NumberFormat.getInstance();
22     nf.setMaximumFractionDigits(2);
23   }
24 %>
25 
26 <%
27     if ("AddInvestor".equals(request.getParameter("action"))) {
28         cal.addInvestor (request.getParameter("investorname"),
29             Integer.parseInt(request.getParameter("investorstart")),
30             Integer.parseInt(request.getParameter("investorend")));
31     }
32 %>
33 
34 <html><body>
35 
36 <p>個人投資家を追加する:<br/>
37 <form action="addinvestor.jsp" method="POST">
38   名前 : <input type="text" name="investorname" value=""><br/>
39   開始年齢 = <input type="text" name="investorstart" value="25">
40   終了年齢 = <input type="text" name="investorend" value="65">
41   <input type="hidden" name="action" value="AddInvestor"><br/>
42   <input type="submit" value="個人投資家を追加する">
43   <INPUT type="button" value="閉じる" onClick="window.close()">
44 </form><br/>
45 
46 <%
47   // Collection <Investor> investors = cal.getInvestors();
48   Collection investors = cal.getInvestors();
49 %>
50 
51 <%=investors.size()%></b>人の個人投資家がデータベースに登録されています。<br/>
52 
53 <table>
54 <tr>
55 <td>名前</td>
56 <td>開始年齢</td>
57 <td>終了年齢</td>
58 </tr>
59 
60 <%
61     for (Iterator iter = investors.iterator(); iter.hasNext();) {
62     Investor investor = (Investoriter.next();
63 %>
64 
65 <tr>
66 <td><%=investor.getName()%></td>
67 <td><%=investor.getStartAge()%></td>
68 <td><%=investor.getEndAge()%></td>
69 </tr>
70 
71 <%
72   }
73 %>
74 </table></p>
75 
76 </body></html>