001 <%@ page contentType="text/html; charset=Shift_JIS" %>
002 <%@ page import="javax.naming.*,
003 java.text.*,
004 java.util.*, org.jboss.security.*,
005 trail.entity.beans.*, trail.security.*,
006 java.security.Principal"%>
007
008 <%!
009 private Calculator cal = null;
010 private NumberFormat nf = null;
011
012 public void jspInit () {
013 try {
014 InitialContext ctx = new InitialContext();
015 cal = (Calculator) ctx.lookup(
016 "EJB3Trail/SecureCalculator/local");
017 } catch (Exception e) {
018 e.printStackTrace ();
019 }
020
021 nf = NumberFormat.getInstance();
022 nf.setMaximumFractionDigits(2);
023 }
024 %>
025
026 <html>
027
028 <%
029 String result = "Not Valid";
030 if ("Calculate".equals(request.getParameter("action"))) {
031 double res = -1;
032 res = cal.calculate (Integer.parseInt(request.getParameter("fund")),
033 Integer.parseInt(request.getParameter("investor")),
034 Double.parseDouble(request.getParameter("saving")));
035 if (res != -1) {
036 result = nf.format(res);
037 }
038 } else if ("Logout".equals(request.getParameter("action"))) {
039 ((HttpSession) request.getSession()).invalidate ();
040 SecurityAssociation.clear ();
041 %>
042 <head><meta http-equiv="REFRESH" content="0; URL=calculator.jsp"></head>
043 <%
044 return;
045 }
046 %>
047
048 <body>
049
050 <p><form action="calculator.jsp" method="POST">
051 現在のユーザは <b><%=((Principal) SecurityAssociation.getPrincipal()).getName()%></b> です
052 <input type="hidden" name="action" value="Logout"><br/>
053 <input type="submit" value="ユーザを変更する">
054 </form></p>
055
056 <p>投資計算プログラム<br/>
057 <form action="calculator.jsp" method="POST">
058 投資会社:
059 <select name="fund">
060 <%
061 Collection funds = cal.getFunds ();
062 for (Iterator iter = funds.iterator(); iter.hasNext();) {
063 Fund fund = (Fund) iter.next();
064 %>
065 <option value="<%=fund.getId()%>"><%=fund.getName()%></option>
066 <%
067 }
068 %>
069 </select>
070 と個人投資家:
071 <select name="investor">
072 <%
073 Collection investors = cal.getInvestors ();
074 for (Iterator iter = investors.iterator(); iter.hasNext();) {
075 Investor investor = (Investor) iter.next();
076 %>
077 <option value="<%=investor.getId()%>"><%=investor.getName()%></option>
078 <%
079 }
080 %>
081 </select> を選択する<br/>
082 月掛金額 = <input type="text" name="saving" value="100">
083 <input type="hidden" name="action" value="Calculate">
084 <input type="submit" value="計算">
085 <INPUT type="button" value="閉じる" onClick="window.close()">
086 </form><br/>
087 合計投資額は <%=result%> です<br/>
088 <br/>
089 データベース内の過去の計算記録<br/>
090 <table>
091 <tr>
092 <td>タイムスタンプ</td>
093 <td>投資会社</td>
094 <td>個人投資家</td>
095 <td>月掛金額</td>
096 <td><b>合計投資額</b></td>
097 </tr>
098
099 <%
100 Collection records = cal.getRecords ();
101 for (Iterator iter = records.iterator(); iter.hasNext();) {
102 TimedRecord record = (TimedRecord) iter.next();
103 %>
104
105 <tr>
106 <td><%=record.getTs()%></td>
107 <td><%=record.getFund().getName()%></td>
108 <td><%=record.getInvestor().getName()%></td>
109 <td><%=nf.format(record.getSaving())%></td>
110 <td><%=nf.format(record.getResult())%></td>
111 </tr>
112
113 <%
114 }
115 %>
116 </table>
117
118 </p>
119
120 </body></html>
|