JAVA 大作业——DAY 6

进度日记:9.3

上午:完成了页面中session的修改,不知道对不对,但是能建立通信,相互传数据(全局变量)。

下午:

实现了dataTable筛选信息功能

学习了html中的table以及下拉菜单

 1       <form action="managerTable.jsp" method="post" >
 2       <table>
 3           <tr>
 4               <td>开始时间:</td><td><input value="20120101"name="startTime" type="text" id="startTime" /></td>
 5               <td>结束时间:</td><td><input value="20130101"name="endTime" type="text" id="endTime" /></td>
 6               <td><input type="submit" id="submit" value="查询"/></td>
 7           </tr>
 8           <tr>
 9               <td>数据类型:</td>
10               <td><select name="dataType">
11                   <option value="0">All</option>
12                   <option value="1">Location</option>
13                   <option value="2">WifiIntensity</option>
14                   <option value="3">Acceleration</option>
15                   <option value="4">LightIntensity</option>
16               </select></td>
17               <td></td><td></td>
18               <td></td>
19         </tr>
20       </table>    
21       </form>

清楚了dataTable.jsp中的表格怎么动态生成。因为可以在jsp中直接调用数据库来进行动态生成表格。逻辑也能在表格中体现。

 1           <% try {
 2             // 连接SQLite的JDBC
 3             // 建立一个数据库名test.db的连接,如果不存在就在当前目录下创建之
 4             Class.forName("org.sqlite.JDBC");
 5             Connection conn = DriverManager.getConnection("jdbc:sqlite:/browser.db");    
 6             Statement stat = conn.createStatement();
 7             long start = System.currentTimeMillis();
 8             String result = "";
 9             if (userID != "") {
10                 String startTime = (String)request.getParameter("startTime");
11                      String endTime = request.getParameter("endTime");
12                      String dataType = request.getParameter("dataType");
13                      if (startTime == null || startTime ==     "") startTime = "00000000";
14                      if (endTime == null || endTime == "") endTime = "99999999";
15                      if (dataType == null || dataType == "") dataType = "0";
16                      ResultSet rs = stat.executeQuery("select * from dataMsg where userID='" 
17                                                      + userID + "';");
18                  %><form action="managerTable.jsp" method="post">
19                  <div style="margin:bottom='100px'"><table border="1" style="margin:bottom='100px'"> <%
20                              %><tr><th>userID</th><th>Time Stamp</th><%
21                              if (dataType.equals("1")) {
22                             %><th>Location</th><%
23                         } else if (dataType.equals("2")) {
24                             %><th>wifi</th><%
25                         } else if (dataType.equals("3")) {
26                             %><th>Acceleration</th><%
27                         } else if (dataType.equals("4")) {
28                              %><th>Light Intensity</th><%
29                         } else {
30                             %><th>Location</th>
31                             <th>wifi</th>
32                             <th>Acceleration</th>
33                             <th>Light Intensity</th><%
34                         }
35                         %><th></th></tr><%
36                 int num = 0;
37                 while (rs.next()) {
38                     timeStamp = rs.getString("timeStamp");
39                     location = rs.getString("longitude") + "," + rs.getString("latitude");
40                     wifi = rs.getString("wifiID") + "," + rs.getString("wifiIntensity") + "," + rs.getString("wifiMAC");
41                     acc = rs.getString("accX") + "," + rs.getString("accY") + "," + rs.getString("accZ");    
42                     lightIntensity = rs.getString("lightIntensity");           
43                     if (timeStamp.compareTo(startTime) > 0 && 
44                         timeStamp.compareTo(endTime) < 0) {
45                         %><tr><td><b><%=userID %></b></td><td><b><%=timeStamp %></b></td><%
46                         if (dataType.equals("1")) {
47                             %><td><%=location %></td><%
48                         } else if (dataType.equals("2")) {
49                             %><td><%=wifi %></td><%
50                         } else if (dataType.equals("3")) {
51                             %><td><%=acc %></td><%
52                         } else if (dataType.equals("4")) {
53                              %><td><%=lightIntensity %></td><%
54                         } else {
55                             %><td><%=location %></td>
56                             <td><%=wifi %></td>
57                             <td><%=acc %></td>
58                             <td><%=lightIntensity %></td><%
59                         }
60                     /*--------------------------------
61                         *  检测到用户
62                       *  画出表格,显示个人资料
63                      ---------------------------------*/        
64                     %><td><input type="checkbox" name=<%=num %>/></td></tr><% 
65                         ++ num;
66                       }//endIf 
67                   }//endWhile %>
68                   </table></div>
69               <%  rs.close();
70             } else {
71                 // 用户名空
72                 result = "用户名空";
73             }
74             long end = System.currentTimeMillis();
75             System.out.println("查询数据耗费时间:" + (end - start) + "\n");
76             conn.close(); // 结束数据库的连接
77         } catch (Exception e) {
78             e.printStackTrace();
79         } // End try %>
80         <div><p><input type="button" value="Select all" />
81         <input type="button" value="Cancel all" />
82         <input type="submit" value="Delete selected" /></p></div>
83         </form>

 

posted @ 2012-09-04 10:10  ReasonHan  阅读(193)  评论(0编辑  收藏  举报