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