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.transaction.*"%>
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 = (Calculatorctx.lookup(
15                   "EJB3Trail/TransCalculator/local");
16     catch (Exception e) {
17       e.printStackTrace ();
18     }
19 
20     nf = NumberFormat.getInstance();
21     nf.setMaximumFractionDigits(2);
22   }
23 %>
24 
25 <%
26     String status = "The update is successful";
27     if ("Update".equals(request.getParameter("action"))) {
28       try {
29         cal.updateExchangeRate(
30             Double.parseDouble(
31                 request.getParameter("newrate")));
32       catch (Exception e) {
33         status = "The update failed";
34       }
35     }
36 %>
37 
38 <html><body>
39 
40 <p>新しい為替で計算記録を更新する<br/>
41 <form action="update.jsp" method="POST">
42   変換レート = <input type="text" name="newrate" value="1.5">
43   <input type="hidden" name="action" value="Update"><br/>
44   <input type="submit" value="更新">
45   <INPUT type="button" value="閉じる" onClick="window.close()">
46 </form><br/>
47 <b>Status:</b> <%=status%><br/>
48 過去の計算記録<br/>
49 <table>
50 <tr>
51 <td>タイムスタンプ</td>
52 <td>投資会社</td>
53 <td>個人投資家</td>
54 <td>月掛金額</td>
55 <td><b>合計投資額</b></td>
56 </tr>
57 
58 <%
59     Collection records = cal.getRecords ();
60     for (Iterator iter = records.iterator(); iter.hasNext();) {
61         TimedRecord record = (TimedRecorditer.next();
62 %>
63 
64 <tr>
65 <td><%=record.getTs()%></td>
66 <td><%=record.getFund().getName()%></td>
67 <td><%=record.getInvestor().getName()%></td>
68 <td><%=nf.format(record.getSaving())%></td>
69 <td><%=nf.format(record.getResult())%></td>
70 </tr>
71 
72 <%
73     }
74 %>
75 </table>
76 
77 </p>
78 </body></html>