首先看一下最终的效果图
传感器地址如下:
数据库图片展示
最终代码:
<%@ page language="java" import="java.util.*" 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">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" type="text/css" href="css/total.css">
<link rel="stylesheet" type="text/css" href="css/iconfont3.css">
<link rel="stylesheet" type="text/css" href="css/sensor.css">
<link rel="stylesheet" type="text/js" href="js/canledar.js">
</head>
<body onload="tm();">
<jsp:include page="common.jsp" />
<!--左边 中间 右边 -->
<div id="mycenter">
<!-- 左边 -->
<div class="cup">
<embed src="images/one.svg" type="image/svg+xml" style="width:787px;height: 799px;" />
</div>
<iframe class="cdown" name="testFrame" src="sensor_dwg.jsp" scrolling="no" frameborder="no" ></iframe>
</div>
</div>
<%--绘制风机气体在图形上---%>
<c:forEach items="${list}" var="i" varStatus="status">
<div>
<c:if test="${status.index == 0}">
<label id="sensor_one">
<i class="iconfont"></i>
<span class="s_g">风速-${i.humi}</span>
</label>
</c:if>
<label id="gas_one">
<c:if test="${status.index == 1}">
<i class="iconfont"></i><span class="s_g">SO2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 2}">
<i class="iconfont"></i><span class="s_g">NO2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 3}">
<i class="iconfont"></i><span class="s_g">H2S-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 4}">
<i class="iconfont"></i><span class="s_g">O2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 5}">
<i class="iconfont"></i><span class="s_g">CO-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 6}">
<i class="iconfont"></i><span class="s_g">TH-${i.humi} ${i.temp}</span>
</c:if>
</label>
<label id="sensor_two">
<c:if test="${status.index == 7}">
<i class="iconfont"></i>
<span class="s_g">SO2-${i.humi}</span>
</c:if>
</label>
<label id="gas_two">
<c:if test="${status.index == 8}">
<i class="iconfont"></i><span class="s_g">NO2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 9}">
<i class="iconfont"></i><span class="s_g">H2S-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 10}">
<i class="iconfont"></i><span class="s_g">TH-${i.humi} ${i.temp}</span><br>
</c:if>
<c:if test="${status.index == 11}">
<i class="iconfont"></i><span class="s_g">CO-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 12}">
<i class="iconfont"></i><span class="s_g">风速-${i.humi}</span>
</c:if>
</label>
<label id="sensor_three">
<c:if test="${status.index == 13}">
<i class="iconfont"></i>
<span class="s_g">CO-${i.humi}</span>
</c:if>
</label>
<label id="gas_three">
<c:if test="${status.index == 14}">
<i class="iconfont"></i><span class="s_g">TH-${i.humi} ${i.temp}</span><br>
</c:if>
<c:if test="${status.index == 15}">
<i class="iconfont"></i><span class="s_g">CO2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 16}">
<i class="iconfont"></i><span class="s_g">O2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 17}">
<i class="iconfont"></i><span class="s_g">气压-${i.humi}</span>
</c:if>
</label>
<label id="gas_four">
<c:if test="${status.index == 18}">
<i class="iconfont"></i><span class="s_g">CO-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 19}">
<i class="iconfont"></i><span class="s_g">TH-${i.humi} ${i.temp}</span>
</c:if>
</label>
<label id="gas_five">
<c:if test="${status.index == 20}">
<i class="iconfont"></i><span class="s_g">气压-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 21}">
<i class="iconfont"></i><span class="s_g">CO-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 22}">
<i class="iconfont"></i><span class="s_g">TH-${i.humi} ${i.temp}</span><br>
</c:if>
<c:if test="${status.index == 23}">
<i class="iconfont"></i><span class="s_g">O2-${i.humi}</span><br>
</c:if>
<c:if test="${status.index == 24}">
<i class="iconfont"></i><span class="s_g">CO2-${i.humi}</span>
</c:if>
</label>
</div>
</c:forEach>
<div id="bottom" style="margin-top:-35%;">
诚信安天下-------铜陵力凡有限责任公司
</div>
</body>
</html>
servlet代码:
package cn.com.servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
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.Test;
import cn.com.jdbc.JdbcUtils_DBCP;
public class Sensor_Page 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 {
Connection conn=null;
Connection conn1=null;
ResultSet rs=null;
ResultSet rs1=null;
PreparedStatement st=null;
PreparedStatement st1=null;
try {
conn = JdbcUtils_DBCP.getConnection();
//1.查询传感器最新的值放在页面上25个地址
String [] tell={"地址为6号","地址为40号","地址为41号","地址为42号","地址为43号","地址为44号","地址为45号","地址为20号","地址为21号","地址为22号","地址为23号","地址为24号","地址为4号","地址为30号","地址为31号","地址为32号","地址为33号","地址为5号","地址为51号","地址为50号","地址为3号","地址为10号","地址为11号","地址为12号","地址为13号"};
List<Test> list=new ArrayList<Test>();
for (int i = 0; i < tell.length; i++) {
String sql="";
if(tell[i]=="地址为45号"||tell[i]=="地址为23号"||tell[i]=="地址为31号"||tell[i]=="地址为50号"||tell[i]=="地址为11号"){
sql="SELECT * FROM test WHERE tell = '"+tell[i]+"' AND tnum='XXXXXX' LIMIT 1";
}else{
sql="select * from test where tell = '"+tell[i]+"' order by date desc limit 1";
}
st=conn.prepareStatement(sql);
rs=st.executeQuery();
while(rs.next()){
String ip=rs.getString(3);
String humi=rs.getString(6);
String temp=rs.getString(7);
conn1 = JdbcUtils_DBCP.getConnection();
if(rs.getString(4)=="XXXXXX"||rs.getString(4).equals("XXXXXX")){
String sqls="SELECT temp FROM test WHERE tell = '"+ip+"' AND hnum='XXXXXX' LIMIT 1";
st1=conn1.prepareStatement(sqls);
rs1=st1.executeQuery();
if(rs1.next()){
temp=rs1.getString(1);
}
}
if(ip.equals("地址为6号")||ip.equals("地址为4号")){
//风速传感器
humi=humi+"m/s";
}
else if(ip.equals("地址为42号")||ip.equals("地址为40号")||ip.equals("地址为43号")||ip.equals("地址为44号")||ip.equals("地址为41号")||ip.equals("地址为44号")||ip=="地址为24号"||ip.equals("地址为20号")||ip.equals("地址为21号")||ip.equals("地址为22号")||ip.equals("地址为30号")||ip.equals("地址为32号")||ip.equals("地址为33号")||ip.equals("地址为51号")||ip.equals("地址为10号")||ip.equals("地址为12号")||ip.equals("地址为13号")){
//气体传感器
humi=humi+"ppm";
}
else if(ip.equals("地址为3号")||ip.equals("地址为5号")){
//大气压传感器
humi=humi+"pa";
}
else if(ip.equals("地址为45号")||ip.equals("地址为23号")||ip.equals("地址为31号")||ip.equals("地址为50号")||ip.equals("地址为11号")){
//温度
temp=temp+"°C";
humi=humi+"RH";
}
Test test=new Test(rs.getInt(1),rs.getString(2),ip, rs.getString(4), rs.getString(5), humi, temp);
list.add(test);
}
}
JdbcUtils_DBCP.release(conn1, st1, rs1);
JdbcUtils_DBCP.release(conn, st, rs);
request.setAttribute("list", list);
//在控制台打印出来
for (Test test : list) {
System.out.println(test.getTell()+":"+test.getHumi()+":"+test.getTemp());
}
//把所有的查询结果都显示出来以后就转到页面上面
request.getRequestDispatcher("/sensor_page.jsp").forward(request, response);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
信息类代码:
package cn.com.gj;
public class Test {
//这个是传感器温室度的封装类
private int id;
private String date;
private String tell;
private String tnum;
private String hnum;
private String humi;
private String temp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTell() {
return tell;
}
public void setTell(String tell) {
this.tell = tell;
}
public String getTnum() {
return tnum;
}
public void setTnum(String tnum) {
this.tnum = tnum;
}
public String getHnum() {
return hnum;
}
public void setHnum(String hnum) {
this.hnum = hnum;
}
public String getHumi() {
return humi;
}
public void setHumi(String humi) {
this.humi = humi;
}
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public Test(int id, String date, String tell, String tnum, String hnum,
String humi, String temp) {
super();
this.id = id;
this.date = date;
this.tell = tell;
this.tnum = tnum;
this.hnum = hnum;
this.humi = humi;
this.temp = temp;
}
public Test(int i, String string, String string2, String string3, String string4, String string5){
super();
}
}
css样式:
@CHARSET "UTF-8";
#sensor_one{
position: relative;
left:654px;
top:-522px;
}
#gas_one{
position: relative;
left:654px;
top:-515px;
}
#sensor_two{
position: relative;
left:411px;
top:-411px;
}
#gas_two{
position: relative;
left:412px;
top:-298px;
}
#sensor_three{
position: relative;
left:595px;
top:-513px;
}
#gas_three{
position: relative;
left:595px;
top:-417px;
}
#gas_four{
position: relative;
left:323px;
top:-370px;
}
#gas_five{
position: relative;
left:547px;
top:-357px;
}
.s_g{
font-size: 12px;
color: #5094d6;
}