01 <%@ page import="javax.naming.*,
02 java.text.*,
03 java.util.*,
04 trail.entity.beans.*,
05 trail.entity.basic.*"%>
06
07 <%!
08 private Calculator cal = null;
09 private NumberFormat nf = null;
10
11 public void jspInit () {
12 try {
13 InitialContext ctx = new InitialContext();
14 cal = (Calculator) ctx.lookup(
15 "EJB3Trail/EntityCalculator/local");
16 } catch (Exception e) {
17 e.printStackTrace ();
18 }
19
20 nf = NumberFormat.getInstance();
21 nf.setMaximumFractionDigits(2);
22 }
23 %>
24
25 <%
26 if ("AddInvestor".equals(request.getParameter("action"))) {
27 cal.addInvestor (request.getParameter("investorname"),
28 Integer.parseInt(request.getParameter("investorstart")),
29 Integer.parseInt(request.getParameter("investorend")));
30 }
31 %>
32
33 <html><body>
34
35 <p>Add a new investor:<br/>
36 <form action="addinvestor.jsp" method="POST">
37 Name : <input type="text" name="investorname" value=""><br/>
38 Start age = <input type="text" name="investorstart" value="25">
39 End age = <input type="text" name="investorend" value="65">
40 <input type="hidden" name="action" value="AddInvestor"><br/>
41 <input type="submit" value="Add Investor">
42 <INPUT type="button" value="Close Window" onClick="window.close()">
43 </form><br/>
44
45 <%
46 // Collection <Investor> investors = cal.getInvestors();
47 Collection investors = cal.getInvestors();
48 %>
49
50 There are <b><%=investors.size()%></b> investors in the database.<br/>
51
52 <table>
53 <tr>
54 <td>Name</td>
55 <td>Start age</td>
56 <td>End age</td>
57 </tr>
58
59 <%
60 for (Iterator iter = investors.iterator(); iter.hasNext();) {
61 Investor investor = (Investor) iter.next();
62 %>
63
64 <tr>
65 <td><%=investor.getName()%></td>
66 <td><%=investor.getStartAge()%></td>
67 <td><%=investor.getEndAge()%></td>
68 </tr>
69
70 <%
71 }
72 %>
73 </table></p>
74
75 </body></html>
|