`calculator.jsp`
`01 <%@ page contentType="text/html; charset=Shift_JIS" %> 02 <%@ page import="trail.jmx.*, org.jboss.mx.util.*, 03 java.text.*, javax.management.*"%> 04 05 <%! 06 private Calculator cal = null; 07 08 public void jspInit () { 09 10 try { 11 MBeanServer server = MBeanServerLocator.locate(); 12 13 // "jboss.j2ee:service=EJB3,name=trail.jmx.CalculatorMBean,type=service" 14 cal = (Calculator) MBeanProxyExt.create( 15 Calculator.class, 16 "trail:service=calculator", 17 server); 18 } catch (Exception e) { 19 e.printStackTrace (); 20 } 21 } 22 %> 23 24 <% 25 String result; 26 int start = 25; 27 int end = 65; 28 double saving = 300.0; 29 try { 30 start = Integer.parseInt(request.getParameter ("start")); 31 end = Integer.parseInt(request.getParameter ("end")); 32 saving = Double.parseDouble(request.getParameter ("saving")); 33 34 NumberFormat nf = NumberFormat.getInstance(); 35 nf.setMaximumFractionDigits(2); 36 result = nf.format(cal.calculate(start, end, saving)); 37 } catch (Exception e) { 38 //e.printStackTrace (); 39 result = "Not valid"; 40 } 41 %> 42 43 <html> 44 <body> 45 46 <p>投資計算プログラム<br/> 47 <form action="calculator.jsp" method="POST"> 48 開始年齢 = <input type="text" name="start" value="<%=start%>"><br/> 49 終了年齢 = <input type="text" name="end" value="<%=end%>"><br/> 50 年成長率 = <%=cal.getGrowthrate()%><br/> 51 月掛金額 = <input type="text" name="saving" value="<%=saving%>"><br/> 52 <input type="submit" value="計算"> 53 <INPUT type="button" value="閉じる" onClick="window.close()"> 54 </form> 55 56 </p> 57 58 <p>最新の計算結果：終了年齢での残高は、 59 <b><%=result%></b></p> 60 61 </body> 62 </html>`