update2.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     if ("yes".equals(request.getParameter("ts"))) {
31       cal.updateTimestamp();
32     }
33     // Commit the changes by removing the bean
34     cal.checkout ();
35     session.setAttribute ("apptrans_cal"null);
36 %>
37 
38 <html>
39 <body>
40 <center>
41   <p><b>The changes have been persisted to the database</b></p>
42   <p><a href="update.jsp">Go back to the update screen</a></p>
43 </center>
44 </body>
45 </html>
46 
47 <%
48   else {
49 %>
50 
51 <html><body>
52 
53 <p>Do you want to update the timestamps as well?<br/>
54 <form action="update2.jsp" method="POST">
55 <input type="hidden" name="action" value="Update"/>
56 <input type="radio" name="ts" value="yes" checked>yes</input>
57 <input type="radio" name="ts" value="no">no</input>
58 <br/>
59 <input type="submit" value="Update"/>
60 <INPUT type="button" value="Close Window" onClick="window.close()"/>
61 </form>
62 </p>
63 </body></html>
64 
65 <%
66   }
67 %>