`filter.jsp`
`01 <%@ page contentType="text/html; charset=Shift_JIS" %> 02 <%@ page import="javax.naming.*, 03 java.text.*, 04 java.util.*, 05 trail.entity.beans.*, trail.entity.query.*"%> 06 07 <%! 08 private Calculator cal = null; 09 private NumberFormat nf = null; 10 11 public void jspInit () { 12 try { 13 InitialContext ctx = new InitialContext(); 14 cal = (Calculator) ctx.lookup( 15 "EJB3Trail/QueryCalculator/local"); 16 } catch (Exception e) { 17 e.printStackTrace (); 18 } 19 20 nf = NumberFormat.getInstance(); 21 nf.setMaximumFractionDigits(2); 22 } 23 %> 24 25 <% 26 Collection records; 27 if ("Filter".equals(request.getParameter("action"))) { 28 double low, high; 29 try { 30 low = Double.parseDouble(request.getParameter("low")); 31 high = Double.parseDouble(request.getParameter("high")); 32 } catch (Exception e) { 33 low = 0.; 34 high = 0.; 35 } 36 records = cal.filterRecords (low, high); 37 // System.err.println("Filtered the records; low=" + low + " high=" + high); 38 } else { 39 records = new ArrayList (); 40 // System.err.println("Empty records"); 41 } 42 %> 43 44 <html><body> 45 46 <p>過去の計算結果を検索する<br/> 47 <form action="filter.jsp" method="POST"> 48 <input type="text" name="low" value="0">から 49 <input type="text" name="high" value="1000000">まで 50 <input type="hidden" name="action" value="Filter"><br/> 51 <input type="submit" value="Search"> 52 <INPUT type="button" value="Close Window" onClick="window.close()"> 53 </form><br/> 54 55 <table> 56 <tr> 57 <td>タイムスタンプ</td> 58 <td>投資会社</td> 59 <td>個人投資家</td> 60 <td>月掛金額</td> 61 <td><b>合計投資額</b></td> 62 </tr> 63 64 <% 65 for (Iterator iter = records.iterator(); iter.hasNext();) { 66 TimedRecord record = (TimedRecord) iter.next(); 67 %> 68 69 <tr> 70 <td><%=record.getTs()%></td> 71 <td><%=record.getFund().getName()%></td> 72 <td><%=record.getInvestor().getName()%></td> 73 <td><%=nf.format(record.getSaving())%></td> 74 <td><%=nf.format(record.getResult())%></td> 75 </tr> 76 77 <% 78 } 79 %> 80 </table> 81 82 83 </p> 84 </body></html>`