`calculator.jsp`
`01 <%@ page contentType="text/html; charset=Shift_JIS" %> 02 <%@ page import="trail.injection.*, javax.naming.*, java.text.*, 03 javax.jms.*, 04 java.sql.Timestamp"%> 05 06 <% 07 if ("send".equals(request.getParameter ("action"))) { 08 09 QueueConnection cnn = null; 10 QueueSender sender = null; 11 QueueSession sess = null; 12 Queue queue = null; 13 14 try { 15 InitialContext ctx = new InitialContext(); 16 queue = (Queue) ctx.lookup("queue/injection"); 17 QueueConnectionFactory factory = 18 (QueueConnectionFactory) ctx.lookup("ConnectionFactory"); 19 cnn = factory.createQueueConnection(); 20 sess = cnn.createQueueSession(false, 21 QueueSession.AUTO_ACKNOWLEDGE); 22 23 } catch (Exception e) { 24 e.printStackTrace (); 25 } 26 27 TextMessage msg = sess.createTextMessage( 28 request.getParameter ("start") + "," + 29 request.getParameter ("end") + "," + 30 request.getParameter ("growthrate") + "," + 31 request.getParameter ("saving") 32 ); 33 // The sent timestamp acts as the message's ID 34 long sent = System.currentTimeMillis(); 35 msg.setLongProperty("sent", sent); 36 37 sender = sess.createSender(queue); 38 sender.send(msg); 39 // sess.commit (); 40 sess.close (); 41 %> 42 43 <html> 44 <head><meta http-equiv="REFRESH" content="3; 45 URL=check.jsp?sent=<%=sent%>"></head> 46 <body> 47 しばらくお待ちください。メッセージが届いているか確認中です。<br/> 48 <a href="calculator.jsp">計算プログラムに戻る</a> 49 </body> 50 </html> 51 52 <% 53 return; 54 55 } else { 56 57 int start = 25; 58 int end = 65; 59 double growthrate = 0.08; 60 double saving = 300.0; 61 %> 62 63 <html> 64 <body> 65 <p>投資計算プログラム<br/> 66 <form action="calculator.jsp" method="POST"> 67 <input type="hidden" name="action" value="send"> 68 開始年齢 = <input type="text" name="start" value="<%=start%>"><br/> 69 終了年齢 = <input type="text" name="end" value="<%=end%>"><br/> 70 年成長率 = <input type="text" name="growthrate" value="<%=growthrate%>"><br/> 71 月掛金額 = <input type="text" name="saving" value="<%=saving%>"><br/> 72 <input type="submit" value="計算"> 73 <INPUT type="button" value="閉じる" onClick="window.close()"> 74 75 </form> 76 </p> 77 </body> 78 </html> 79 80 <% 81 return; 82 } 83 %>`