update.jsp
01 <%@ page import="javax.naming.*,
02                  java.text.*,
03                  java.util.*,
04                  trail.entity.beans.*, trail.transaction.*"%>
05 
06 <%!
07   private Calculator cal = null;
08   private NumberFormat nf = null;
09 
10   public void jspInit () {
11     try {
12       InitialContext ctx = new InitialContext();
13       cal = (Calculatorctx.lookup(
14                   "EJB3Trail/TransCalculator/local");
15     catch (Exception e) {
16       e.printStackTrace ();
17     }
18 
19     nf = NumberFormat.getInstance();
20     nf.setMaximumFractionDigits(2);
21   }
22 %>
23 
24 <%
25     String status = "The update is successful";
26     if ("Update".equals(request.getParameter("action"))) {
27       try {
28         cal.updateExchangeRate(
29             Double.parseDouble(
30                 request.getParameter("newrate")));
31       catch (Exception e) {
32         status = "The update failed";
33       }
34     }
35 %>
36 
37 <html><body>
38 
39 <p>Update the calculation records with a new currency<br/>
40 <form action="update.jsp" method="POST">
41   Exchange rate = <input type="text" name="newrate" value="1.5">
42   <input type="hidden" name="action" value="Update"><br/>
43   <input type="submit" value="Update">
44   <INPUT type="button" value="Close Window" onClick="window.close()">
45 </form><br/>
46 <b>Status:</b> <%=status%><br/>
47 All records from past calculations<br/>
48 <table>
49 <tr>
50 <td>Time stamp</td>
51 <td>Fund</td>
52 <td>Investor</td>
53 <td>Monthly savings</td>
54 <td><b>Total investment</b></td>
55 </tr>
56 
57 <%
58     Collection records = cal.getRecords ();
59     for (Iterator iter = records.iterator(); iter.hasNext();) {
60         TimedRecord record = (TimedRecorditer.next();
61 %>
62 
63 <tr>
64 <td><%=record.getTs()%></td>
65 <td><%=record.getFund().getName()%></td>
66 <td><%=record.getInvestor().getName()%></td>
67 <td><%=nf.format(record.getSaving())%></td>
68 <td><%=nf.format(record.getResult())%></td>
69 </tr>
70 
71 <%
72     }
73 %>
74 </table>
75 
76 </p>
77 </body></html>