calculator.jsp
01 <%@ page import="trail.mdpojo.*, javax.naming.*, java.text.*,
02                  org.jboss.ejb3.mdb.*"%>
03 
04 <%
05   if ("send".equals(request.getParameter ("action"))) {
06 
07     int start = Integer.parseInt(request.getParameter ("start"));
08     int end = Integer.parseInt(request.getParameter ("end"));
09     double growthrate = Double.parseDouble(request.getParameter ("growthrate"));
10     double saving = Double.parseDouble(request.getParameter ("saving"));
11 
12     // The sent timestamp acts as the message's ID
13     long sent = System.currentTimeMillis();
14 
15     Calculator cal = null;
16     ProducerManager manager = null;
17     try {
18 
19       InitialContext ctx = new InitialContext();
20       cal = (Calculatorctx.lookup(
21                   Calculator.class.getName());
22       // cal = (Calculator) ctx.lookup(
23       //             "EJB3Trail/MdpojoCalculator/remote");
24       ProducerObject po = (ProducerObjectcal;
25       manager = po.getProducerManager();
26 
27     catch (Exception e) {
28       e.printStackTrace ();
29     }
30 
31     manager.connect()// internally create a JMS connection
32     try {
33       cal.doCalculation(sent, start, end,
34                         growthrate, saving);
35     finally {
36       manager.close()// clean up the JMS connection
37     }
38 
39 %>
40 
41 <html>
42 <head><meta http-equiv="REFRESH" content="3;
43                 URL=check.jsp?sent=<%=sent%>"></head>
44   <body>
45     Please wait while I am checking whether the message has arrived.<br/>
46     <a href="calculator.jsp">Go back to Calculator</a>
47   </body>
48 </html>
49 
50 <%
51     return;
52 
53   else {
54 
55     int start = 25;
56     int end = 65;
57     double growthrate = 0.08;
58     double saving = 300.0;
59 %>
60 
61 <html>
62 <body>
63 <p>Investment calculator<br/>
64 <form action="calculator.jsp" method="POST">
65   <input type="hidden" name="action" value="send">
66   Start age = <input type="text" name="start" value="<%=start%>"><br/>
67   End age   = <input type="text" name="end" value="<%=end%>"><br/>
68   Annual Growth Rate = <input type="text" name="growthrate" value="<%=growthrate%>"><br/>
69   Montly Saving = <input type="text" name="saving" value="<%=saving%>"><br/>
70   <input type="submit" value="Calculate">
71   <INPUT type="button" value="Close Window" onClick="window.close()">
72 </form>
73 </p>
74 </body>
75 </html>
76 
77 <%
78     return;
79   }
80 %>