`addfund.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 = (Calculator) ctx.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 ("AddFund".equals(request.getParameter("action"))) { 28 cal.addFund (request.getParameter("fundname"), 29 Double.parseDouble(request.getParameter("fundrate"))); 30 } 31 %> 32 33 <html><body> 34 35 <p>投資会社を追加する:<br/> 36 <form action="addfund.jsp" method="POST"> 37 投資会社名 : <input type="text" name="fundname" value=""> 38 年成長率 : <input type="text" name="fundrate" value="0.05"> 39 <input type="hidden" name="action" value="AddFund"><br/> 40 <input type="submit" value="投資会社を追加する"> 41 <INPUT type="button" value="閉じる" onClick="window.close()"> 42 </form><br/> 43 44 <% 45 // Collection <Fund> funds = cal.getFunds(); 46 Collection funds = cal.getFunds(); 47 %> 48 49 <%=funds.size()%></b>社の投資会社がデータベースに登録されています。<br/> 50 51 <table> 52 <tr> 53 <td>投資会社名</td> 54 <td>年成長率</td> 55 </tr> 56 57 <% 58 for (Iterator iter = funds.iterator(); iter.hasNext();) { 59 Fund fund = (Fund) iter.next(); 60 %> 61 62 <tr> 63 <td><%=fund.getName()%></td> 64 <td><%=nf.format(fund.getGrowthrate())%></td> 65 </tr> 66 67 <% 68 } 69 %> 70 </table></p> 71 72 </body></html>`