`addfund.jsp`
`01 <%@ page contentType="text/html; charset=Shift_JIS" %> 02 <%@ page import="javax.naming.*, 03 java.text.*, 04 java.util.*, org.jboss.security.*, 05 trail.entity.beans.*, trail.security.*, 06 java.security.Principal"%> 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/SecureCalculator/local"); 17 } catch (Exception e) { 18 e.printStackTrace (); 19 } 20 21 nf = NumberFormat.getInstance(); 22 nf.setMaximumFractionDigits(2); 23 } 24 %> 25 26 <html> 27 28 <% 29 if ("AddFund".equals(request.getParameter("action"))) { 30 try { 31 cal.addFund (request.getParameter("fundname"), 32 Double.parseDouble(request.getParameter("fundrate"))); 33 } catch (Exception e) { 34 %> 35 <head><meta http-equiv="REFRESH" content="0; URL=error.html"></head> 36 <% 37 return; 38 } 39 } else if ("Logout".equals(request.getParameter("action"))) { 40 ((HttpSession) request.getSession()).invalidate (); 41 SecurityAssociation.clear (); 42 %> 43 <head><meta http-equiv="REFRESH" content="0; URL=addfund.jsp"></head> 44 <% 45 return; 46 } 47 %> 48 49 <body> 50 51 <p><form action="addfund.jsp" method="POST"> 52 現在のユーザは <b><%=((Principal) SecurityAssociation.getPrincipal()).getName()%></b> です 53 <input type="hidden" name="action" value="Logout"><br/> 54 <input type="submit" value="ユーザを変更する"> 55 </form></p> 56 57 <p>投資会社を追加する:<br/> 58 <form action="addfund.jsp" method="POST"> 59 投資会社名 : <input type="text" name="fundname" value=""> 60 年成長率 : <input type="text" name="fundrate" value="0.05"> 61 <input type="hidden" name="action" value="AddFund"><br/> 62 <input type="submit" value="投資会社を追加する"> 63 <INPUT type="button" value="閉じる" onClick="window.close()"> 64 </form><br/> 65 66 <% 67 // Collection <Fund> funds = cal.getFunds(); 68 Collection funds = cal.getFunds(); 69 %> 70 71 <b><%=funds.size()%></b>社の投資会社がデータベースに登録されています。<br/> 72 73 <table> 74 <tr> 75 <td>投資会社名</td> 76 <td>年成長率</td> 77 </tr> 78 79 <% 80 for (Iterator iter = funds.iterator(); iter.hasNext();) { 81 Fund fund = (Fund) iter.next(); 82 %> 83 84 <tr> 85 <td><%=fund.getName()%></td> 86 <td><%=nf.format(fund.getGrowthrate())%></td> 87 </tr> 88 89 <% 90 } 91 %> 92 </table></p> 93 94 </body></html>`