update.jsp
01 <%@ page import="javax.naming.*,
02                  java.text.*,
03                  java.util.*,
04                  trail.entity.beans.*, trail.apptrans.*"%>
05 
06 <%!
07   private NumberFormat nf = null;
08 
09   public void jspInit () {
10     nf = NumberFormat.getInstance();
11     nf.setMaximumFractionDigits(2);
12   }
13 %>
14 
15 <%
16   Calculator cal =
17       (Calculatorsession.getAttribute("apptrans_cal");
18   if (cal == null) {
19     try {
20       InitialContext ctx = new InitialContext();
21       cal = (Calculatorctx.lookup(
22                   "EJB3Trail/ApptransCalculator/local");
23       session.setAttribute ("apptrans_cal", cal);
24     catch (Exception e) {
25       e.printStackTrace ();
26     }
27   }
28 
29   if ("Update".equals(request.getParameter("action"))) {
30     cal.updateExchangeRate(
31           Double.parseDouble(
32               request.getParameter("newrate")));
33 %>
34 <html>
35 <head><meta http-equiv="REFRESH" content="3; URL=update2.jsp"></head>
36   <body>
37     Please hold on ...
38   </body>
39 </html>
40 <%
41   else {
42 %>
43 
44 <html><body>
45 
46 <p>Update the calculation records with a new currency<br/>
47 <form action="update.jsp" method="POST">
48   Exchange rate = <input type="text" name="newrate" value="1.1">
49   <input type="hidden" name="action" value="Update"><br/>
50   <input type="submit" value="Update">
51   <INPUT type="button" value="Close Window" onClick="window.close()">
52 </form><br/>
53 
54 Calculation records currently in the database<br/>
55 <table>
56 <tr>
57 <td>Time stamp</td>
58 <td>Fund</td>
59 <td>Investor</td>
60 <td>Monthly savings</td>
61 <td><b>Total investment</b></td>
62 </tr>
63 
64 <%
65     Collection records = cal.getRecords ();
66     for (Iterator iter = records.iterator(); iter.hasNext();) {
67       TimedRecord record = (TimedRecorditer.next();
68 %>
69 
70 <tr>
71 <td><%=record.getTs()%></td>
72 <td><%=record.getFund().getName()%></td>
73 <td><%=record.getInvestor().getName()%></td>
74 <td><%=nf.format(record.getSaving())%></td>
75 <td><%=nf.format(record.getResult())%></td>
76 </tr>
77 
78 <%
79     }
80 %>
81 </table>
82 </p>
83 </body></html>
84 
85 <%
86   }
87 %>