定位系統之井下人員狀況
阿新 • • 發佈:2018-12-12
我需要實現如下圖的功能 後臺需要實現的功能 1.統計處於不同井段的人員的數目 2.查詢出各個井段人員的名稱 前端: 迴圈遍歷到頁面上 美化頁面 首先要知道模糊查詢語句和把兩張表關聯的語句: 設定表中欄位的唯一性: ALTER TABLE USER ADD UNIQUE(number); 中途報錯: 錯誤原因: 程式碼如下: 實現的實際頁面如下圖 實現的程式碼如下: servlet
package cn.com.servlet; import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cn.com.gj.DoubleStr; import cn.com.lf.JdbcUtils; public class Underperson_status extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1.統計處於不同井段的人員的數目 //2.查詢出各個井段人員的名稱 Date da=new Date(); SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd"); String time=sim.format(da); String sql="select * from yh where time like '"+ time + "%' and state=1 "; System.out.println(sql); ResultSet rs=JdbcUtils.select(sql, null); List<DoubleStr> list=new ArrayList<DoubleStr>(); int count0 = 0,count1= 0,count2= 0,count3= 0,count4= 0,count5= 0,count6= 0; String str0=""; String str1=""; String str2=""; String str3=""; String str4=""; String str5=""; String str6=""; try { while(rs.next()){ //1.1把基站和名字一一對應儲存起來 String name=""; String bs=rs.getString(2); String number=rs.getString(1); String sqls="select username from user where number=?"; String sz[]={number}; ResultSet rs1=JdbcUtils.select(sqls, sz); if(rs1.next()){ name=rs1.getString(1); } //-290m if(bs.equals("040")||bs.equals("031")||bs.equals("034")||bs.equals("038")||bs.equals("033")||bs.equals("039")){ count0++; str0=str0+" "+name; } //地表 if(bs.equals("030")||bs.equals("017")||bs.equals("028")||bs.equals("014")||bs.equals("023")||bs.equals("029")){ count1++; str1=str1+" "+name; } //-130m if(bs.equals("022")||bs.equals("020")||bs.equals("021")||bs.equals("015")){ count2++; str2=str2+" "+name; } //-240m if(bs.equals("024")||bs.equals("027")){ count3++; str3=str3+" "+name; } //斜井 if(bs.equals("012")||bs.equals("013")||bs.equals("019")){ count4++; str4=str4+" "+name; } //-340m if(bs.equals("037")||bs.equals("025")||bs.equals("032")){ count5++; str5=str5+" "+name; } //-400m if(bs.equals("016")||bs.equals("036")||bs.equals("026")||bs.equals("035")||bs.equals("011")){ count6++; str6=str6+" "+name; } } DoubleStr dou0=new DoubleStr(Integer.toString(count0),str0) ; list.add(dou0); DoubleStr dou1=new DoubleStr(Integer.toString(count1),str1) ; list.add(dou1); DoubleStr dou2=new DoubleStr(Integer.toString(count2),str2) ; list.add(dou2); DoubleStr dou3=new DoubleStr(Integer.toString(count3),str3) ; list.add(dou3); DoubleStr dou4=new DoubleStr(Integer.toString(count4),str4) ; list.add(dou4); DoubleStr dou5=new DoubleStr(Integer.toString(count5),str5) ; list.add(dou5); DoubleStr dou6=new DoubleStr(Integer.toString(count6),str6) ; list.add(dou6); int sum=count0+count1+count2+count3+count4+count5+count6; String sm=Integer.toString(sum); System.out.println(sm); request.setAttribute("list", list); request.setAttribute("sm", sm); request.getRequestDispatcher("Underperson_status.jsp").forward(request, response); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
jsp程式碼如下:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>華金礦業-井下人員狀況</title> <!-- 首頁 --> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <link rel="stylesheet" type="text/css" href="css/index.css"> <script type="text/javascript"> function hide(){ var id=document.getElementById("center_img"); var name=id.getAttribute("name"); var left=document.getElementById("center-left"); if(name=="block"){ left.setAttribute("style", "display:none;"); id.setAttribute("name", "none"); }if(name=="none"){ left.setAttribute("style", "display:block;"); id.setAttribute("name", "block"); } } function display(a){ var elements=[]; //獲得所有的li標籤 var list=document.getElementsByTagName("li"); var len=list.length;//獲得長度 //把class=sub-menu的li都放在集合裡面 for(var i=0;i<len;i++){ if(list[i].className== "sub-menu"){ elements[elements.length]=list[i]; } } /*把所有的隱藏 */ for(var i=0;i<elements.length;i++){ //獲得下面的ul var ul=elements[i].childNodes[3]; /* 設定屬性為隱藏 */ ul.setAttribute("style","display:none"); /* 點選當前元素的Ul設定可見 */ } /* 對所有的input背景顏色設定 */ var tree=document.getElementsByName("tree"); for(var i=0;i<tree.length;i++){ tree[i].setAttribute("style", "background-color:#E1F1FD;"); } var input=document.getElementById(a); input.setAttribute("style", "background-color:#5094D6;"); var ula=input.parentNode; var lla=ula.childNodes; for(var i=0;i<lla.length;i++){ if(lla[i].nodeName=='UL'){ lla[i].setAttribute("style","display:block"); } } } /*獲取當前的日期和時間 */ function tm(){ var today = new Date(); var year=today.getFullYear(); var month=today.getMonth()+1; var day=today.getDay(); var tm=year+"年"+month+"月"+day+"日"+" "+today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); ; var rq=document.getElementById("rq"); rq.innerHTML=tm; } </script> </head> <body onload="tm();"> <!-- 上 --> <div id="up"> <div id="up_left"> <ul> <li style="font-size:12px;">銅陵華金礦業有限責任公司</li> <li>井下綜合監管系統</li> </ul> </div> <table id="up_right"> <tr> <td class="prompt">您好!<%=request.getParameter("username") %></td> <td class="prompt">[華金礦業]:</td> <td class="prompt" id="rq"></td> </tr> <tr> <td class="prompt">密碼</td> <td class="prompt">桌面</td> <td class="prompt">登出</td> </tr> </table> </div> <div style="width:102%;height: 50px;background-color: #4891C6;position: relative;margin-top: -14px;margin-left: -7px;"></div> <!--中 --> <div id="centers"> <div id="center-left"> <input type="button" value="功能選單" class="view"> <ul id="all"> <!-- 第一個選單 --> <li class="sub-menu"> <input type="button" value="圖形展現" class="button" name="tree" id="jpg" onclick="display(this.id);"> <ul style="display: none;"> <li><a href="total_picture.jsp">實時總圖</a></li> <li><a href="role_position.jsp" >軌跡定位</a></li> </ul> </li> <!-- 第二個選單 --> <li class="sub-menu"> <input type="button" value="人員定位" class="button" name="tree" id="people" onclick="display(this.id);"> <ul style="display: none;"> <li>井下人員狀況</li> <li>LED通知管理</li> <li>LED顯示管理</li> <li>大螢幕輸出</li> <li>人員定位搜尋</li> <li>人員考勤搜尋</li> <li>排程統計</li> </ul> </li> <!-- 第三個選單 --> <li class="sub-menu"> <input type="button" value="環境監測" class="button" name="tree" id="supervise" onclick="display(this.id);"> <ul style="display: none;"> <li>環境測試總圖</li> <li>環境監測資料查詢</li> <li>環境報警資料查詢</li> </ul> </li> <!-- 第四個選單 --> <li class="sub-menu"> <input type="button" value="查詢統計" class="button" name="tree" id="select" onclick="display(this.id);"> <ul style="display: none;"> <li>人員報警查詢</li> <li>超時人員查詢</li> <li>裝置工作狀況</li> <li>裝置工作狀態查詢</li> </ul> </li> <!-- 第五個選單 --> <li class="sub-menu"> <input type="button" value="基礎資訊管理" class="button" name="tree" id="information" onclick="display(this.id);"> <ul style="display: none;"> <li>基站定義</li> <li>採集基站定義</li> <li>採集裝置定義</li> <li><a href="/Socket/Personnel_definition">人員定義</a></li> <li>工種定義</li> <li>職務定義</li> <li>帶班領導定義</li> </ul> </li> <!-- 第六個選單 --> <li class="sub-menu"> <input type="button" value="系統管理" class="button" name="tree" id="system" onclick="display(this.id)"> <ul style="display: none;"> <li>機構定義</li> <li>使用者定義</li> </ul> </li> </ul> <!--隱藏下面的具體位元組 --> </div> <div id="center-right"> <!-- 人員資訊介面--> <div id="peo_head">井下人員狀況</div> <br> <div id="peo_info"> <table style="width: 99%;border-collapse:separate; border-spacing:3px;"> <tr class="trr"> <td rowspan="14" style="width: 7%;">當前井下人數:<br><br>總共 <%=request.getAttribute("sm") %>人 </td> <td>井段</td><td class="ps">人員名稱</td></tr> <c:forEach items="${list}" var="i" varStatus="status"> <c:if test="${status.index == 1}"> <tr style="background-color: white;" class="trr"><td>-290m</td> <td rowspan="2" class="ps" colspan="3" style="width:73%;">${i.two}</td></tr> <tr style="background-color: white"> <td >總計:${i.one} 人</td> </tr> </c:if> <c:if test="${status.index == 2}"> <tr style="background-color: #f2f7fa" class="trr"><td>地表</td><td rowspan="2" colspan="3" class="ps">${i.two}</td></tr> <tr style="background-color: #f2f7fa" class="trr"><td>總計:${i.one} 人</td></tr> </c:if> <c:if test="${status.index == 3}"> <tr style="background-color: white" class="trr"><td>-130m</td><td rowspan="2" colspan="3" class="ps">${i.two}</td></tr> <tr style="background-color: white" class="trr"><td>總計:${i.one} 人</td></tr> </c:if> <c:if test="${status.index == 4}"> <tr style="background-color: #f2f7fa" class="trr"><td>-240m</td><td rowspan="2" colspan="3" class="ps">${i.two}</td></tr> <tr style="background-color: #f2f7fa" class="trr"><td>總計:${i.one} 人</td></tr> </c:if> <c:if test="${status.index == 5}"> <tr style="background-color: white" class="trr"><td>斜井</td><td rowspan="2" colspan="3" class="ps">${i.two}</td></tr> <tr style="background-color: white" class="trr"><td>總計:${i.one} 人</td></tr> </c:if> <c:if test="${status.index == 6}"> <tr style="background-color: #f2f7fa" class="trr"><td>-340m</td><td rowspan="2" colspan="3" class="ps">${i.two}</td></tr> <tr style="background-color: #f2f7fa" class="trr"><td>總計:${i.one} 人</td></tr> </c:if> <c:if test="${status.index == 7}"> <tr style="background-color: white" class="trr"><td>-400m</td><td rowspan="2" colspan="3" class="ps">${i.two}</td></tr> <tr style="background-color: white" class="trr"><td>總計:${i.one} 人</td></tr> </c:if> </c:forEach> </table> </div> </div> <!-- 遍歷資料庫裡面的集合--> </div> <!--下 --> <div id="bottom"> 誠信安天下-------銅陵力凡有限責任公司 </div> </body> <style> #peo_info{ background-color:#e2e7ea; width:105%; height: 430px; position: relative; margin-left: 23px; } .trr{ height: 30px; font-size: 14px; } #peo_head{ width:119%; height: 40px; background-color:#8dc2e6; text-align: center; color:white; position: relative; margin-top: -2px; padding-top: 19px; } #peo_info td{ width: 15%; text-align: center; } </style> </html>