`update.jsp`
`01 <%@ page contentType="text/html; charset=Shift_JIS" %> 02 <%@ page import="javax.naming.*, 03 java.text.*, 04 java.util.*, 05 trail.entity.beans.*, trail.apptrans.*"%> 06 07 <%! 08 private NumberFormat nf = null; 09 10 public void jspInit () { 11 nf = NumberFormat.getInstance(); 12 nf.setMaximumFractionDigits(2); 13 } 14 %> 15 16 <% 17 Calculator cal = 18 (Calculator) session.getAttribute("apptrans_cal"); 19 if (cal == null) { 20 try { 21 InitialContext ctx = new InitialContext(); 22 cal = (Calculator) ctx.lookup( 23 "EJB3Trail/ApptransCalculator/local"); 24 session.setAttribute ("apptrans_cal", cal); 25 } catch (Exception e) { 26 e.printStackTrace (); 27 } 28 } 29 30 if ("Update".equals(request.getParameter("action"))) { 31 cal.updateExchangeRate( 32 Double.parseDouble( 33 request.getParameter("newrate"))); 34 %> 35 <html> 36 <head><meta http-equiv="REFRESH" content="3; URL=update2.jsp"></head> 37 <body> 38 しばらくお待ちください... 39 </body> 40 </html> 41 <% 42 } else { 43 %> 44 45 <html><body> 46 47 <p>新しい為替で計算記録を更新する<br/> 48 <form action="update.jsp" method="POST"> 49 変換レート = <input type="text" name="newrate" value="1.1"> 50 <input type="hidden" name="action" value="Update"><br/> 51 <input type="submit" value="更新"> 52 <INPUT type="button" value="閉じる" onClick="window.close()"> 53 </form><br/> 54 55 現在のデータベース内の計算記録<br/> 56 <table> 57 <tr> 58 <td>タイムスタンプ</td> 59 <td>投資会社</td> 60 <td>個人投資家</td> 61 <td>月掛金額</td> 62 <td><b>合計投資額</b></td> 63 </tr> 64 65 <% 66 Collection records = cal.getRecords (); 67 for (Iterator iter = records.iterator(); iter.hasNext();) { 68 TimedRecord record = (TimedRecord) iter.next(); 69 %> 70 71 <tr> 72 <td><%=record.getTs()%></td> 73 <td><%=record.getFund().getName()%></td> 74 <td><%=record.getInvestor().getName()%></td> 75 <td><%=nf.format(record.getSaving())%></td> 76 <td><%=nf.format(record.getResult())%></td> 77 </tr> 78 79 <% 80 } 81 %> 82 </table> 83 </p> 84 </body></html> 85 86 <% 87 } 88 %>`