<%@ page contentType="text/html; charset=Shift_JIS" %>
<%@ page import="trail.jmx.*, org.jboss.mx.util.*,
                 java.text.*, javax.management.*"%>

<%!
  private Calculator cal = null;

  public void jspInit () {

    try {
      MBeanServer server = MBeanServerLocator.locate();

      // "jboss.j2ee:service=EJB3,name=trail.jmx.CalculatorMBean,type=service"
      cal = (Calculator) MBeanProxyExt.create(
          Calculator.class,
          "trail:service=calculator",
          server);
    } catch (Exception e) {
      e.printStackTrace ();
    }
  }
%>

<%
  String result;
  int start = 25;
  int end = 65;
  double saving = 300.0;
  try {
    start = Integer.parseInt(request.getParameter ("start"));
    end = Integer.parseInt(request.getParameter ("end"));
    saving = Double.parseDouble(request.getParameter ("saving"));

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    result = nf.format(cal.calculate(start, end, saving));
  } catch (Exception e) {
    //e.printStackTrace ();
    result = "Not valid";
  }
%>

<html>
<body>

<p>投資計算プログラム<br/>
<form action="calculator.jsp" method="POST">
  開始年齢 = <input type="text" name="start" value="<%=start%>"><br/>
  終了年齢 = <input type="text" name="end" value="<%=end%>"><br/>
  年成長率 = <%=cal.getGrowthrate()%><br/>
  月掛金額 = <input type="text" name="saving" value="<%=saving%>"><br/>
  <input type="submit" value="計算">
  <INPUT type="button" value="閉じる" onClick="window.close()">
</form>

</p>

<p>最新の計算結果：終了年齢での残高は、
<b><%=result%></b></p>

</body>
</html>