`calculator.jsp`
`01 <%@ page contentType="text/html; charset=Shift_JIS" %> 02 <%@ page import="trail.mdpojo.*, javax.naming.*, java.text.*, 03 org.jboss.ejb3.mdb.*"%> 04 05 <% 06 if ("send".equals(request.getParameter ("action"))) { 07 08 int start = Integer.parseInt(request.getParameter ("start")); 09 int end = Integer.parseInt(request.getParameter ("end")); 10 double growthrate = Double.parseDouble(request.getParameter ("growthrate")); 11 double saving = Double.parseDouble(request.getParameter ("saving")); 12 13 // The sent timestamp acts as the message's ID 14 long sent = System.currentTimeMillis(); 15 16 Calculator cal = null; 17 ProducerManager manager = null; 18 try { 19 20 InitialContext ctx = new InitialContext(); 21 cal = (Calculator) ctx.lookup( 22 Calculator.class.getName()); 23 // cal = (Calculator) ctx.lookup( 24 // "EJB3Trail/MdpojoCalculator/remote"); 25 ProducerObject po = (ProducerObject) cal; 26 manager = po.getProducerManager(); 27 28 } catch (Exception e) { 29 e.printStackTrace (); 30 } 31 32 manager.connect(); // internally create a JMS connection 33 try { 34 cal.doCalculation(sent, start, end, 35 growthrate, saving); 36 } finally { 37 manager.close(); // clean up the JMS connection 38 } 39 40 %> 41 42 <html> 43 <head><meta http-equiv="REFRESH" content="3; 44 URL=check.jsp?sent=<%=sent%>"></head> 45 <body> 46 しばらくお待ちください。メッセージが届いているか確認中です。<br/> 47 <a href="calculator.jsp">計算プログラムに戻る</a> 48 </body> 49 </html> 50 51 <% 52 return; 53 54 } else { 55 56 int start = 25; 57 int end = 65; 58 double growthrate = 0.08; 59 double saving = 300.0; 60 %> 61 62 <html> 63 <body> 64 <p>投資計算プログラム<br/> 65 <form action="calculator.jsp" method="POST"> 66 <input type="hidden" name="action" value="send"> 67 開始年齢 = <input type="text" name="start" value="<%=start%>"><br/> 68 終了年齢 = <input type="text" name="end" value="<%=end%>"><br/> 69 年成長率 = <input type="text" name="growthrate" value="<%=growthrate%>"><br/> 70 月掛金額 = <input type="text" name="saving" value="<%=saving%>"><br/> 71 <input type="submit" value="計算"> 72 <INPUT type="button" value="閉じる" onClick="window.close()"> 73 </form> 74 </p> 75 </body> 76 </html> 77 78 <% 79 return; 80 } 81 %>`