小弟刚刚接触jsp想请各位精通sql语句的帮我写一个check.jsp页的代码 主要实现的功能是 根据用户选择的复选框 查询数据库表中的不同字段 查询条件还有一个是时间数据库表结构如下
根据选择的设备mac 和 时间 还有在复选框里选择的端口(c1\c2\c3\c4\c5\c6) 求和... 请高手
在check页面里显示已选端口对应数据库字段值的和,比如复选择的是端口一和端口三,在check页里就显示端口一的和为: 端口三的和为:
页面我已经做好了 效果如下:
代码如下:
----------------------------------------------------------------------------------------------
<%@ page import="com.xx.db.DAO" %>
<scrip>
function CompareDate(d1,d2)
{
return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}
function tijiao()
{var a=document.getElementById("a").value;
var b=document.getElementById("b").value;
var c=document.getElementById("c").value;var a1=document.getElementById("a1").value;var b1=document.getElementById("b1").value;var c1=document.getElementById("c1").value;var current_time = a+"-"+b+"-"+c+" 0:00";
var stop_time = a1+"-"+b1+"-"+c1+" 0:00";if( document.getElementById("dk1").checked==true || document.getElementById("dk2").checked==true || document.getElementById("dk3").checked==true || document.getElementById("dk4").checked==true || document.getElementById("dk5").checked==true || document.getElementById("dk6").checked==true)
{ var obj = document.getElementById("A4"); //取下拉框 选中的值
var macall="";
for (var i=0; i < obj.length; i++)
{
if(i==obj.length-1)
{
macall+=obj.options[i].value;
}else
{
macall+=obj.options[i].value+",";
}
}
document.getElementById("allmac").value=macall;
else
{
alert("至少选中一端口");
}}</script>
<body >
<%
Calendar c=new GregorianCalendar();//新建日期对象
int year=c.get(Calendar.YEAR);//获取年份
int month=c.get(Calendar.MONTH)+1;//获取月份
int day=c.get(Calendar.DATE);//获取日期
String url=request.getContextPath();
%>
<form method="post" action="check.jsp" name="form1">
<input type="hidden" name="fanhui" value="/Action_4.do?action=getmac">
<input type="hidden" name="act" value="device">
<input type="hidden" name="allmac" value="">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="10" class="font_1">
<tr>
<td width="166" rowspan="3"> </td>
<td width="157" rowspan="3"> </td>
<td width="20" height="-4" class="font_1" style="cursor:hand" onClick="filtrate('')" > </td>
<td width="393" rowspan="3"> <div align="left">
<input type="checkbox" name="dk1" id="dk1" value="1" checked>
端口一
<input type="checkbox" name="dk2" id="dk2" value="2" checked>
端口二
<input type="checkbox" name="dk3" id="dk3" value="3" checked>
端口三
<input type="checkbox" name="dk4" id="dk4" value="4" checked>
端口四
<input type="checkbox" name="dk5" id="dk5" value="5" checked>
端口五
<input type="checkbox" name="dk6" id="dk6" value="6" checked>
端口六 </div></td>
</tr>
<tr>
<td height="3" class="font_1" style="cursor:hand" onClick="filtrate('')" > </td>
</tr>
<tr>
<td width="20" height="11" class="font_1" style="cursor:hand" onClick="filtrate('')" > </td>
</tr>
</table>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="font_1">
<tr>
<td width="12px" ><img src="<%=url%>/html_temp/table_10.gif" width="12" height="16" /></td>
<td background="<%=url%>/html_temp/table_09.gif"></td>
<td width="14px" ><img src="<%=url%>/html_temp/table_08.gif" width="14" height="16" /></td>
</tr>
<tr>
<td background="<%=url%>/html_temp/table_03.gif"></td>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_z">
<tr bgcolor="#EEF8F7">
<td > </td>
</tr>
<tr bgcolor="#EEF8F7">
<td ><div align="center">开 始 时 间
<select size="1" name="sy" id="a" style="position: relative;width:100; background:#FFFFFF;">
<%
for(int i=1;i<=40;i++)
{ %>
<option value = "<%=2007+i%>"><%=2007+i%> </option>
<% }%>
</select>
年 :
<select size="1" name="sm" id="b" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=12;i++){%>
<option value = "<%=i%>"> <%=i%> </option>
<%}%>
</select>
月 :
<select size="1" name="sd" id="c" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=31;i++){%>
<option value = "<%=i%>"> <%=i%> </option>
<%}%>
</select>
日 </div></td>
</tr>
<tr bgcolor="#EEF8F7">
<td > </td>
</tr>
<tr bgcolor="#EEF8F7">
<td ><div align="center">结 束 时 间
<select size="1" name="ey" id="a1" style="position: relative;width:100; background:#FFFFFF;">
<%
for(int i=1;i<=40;i++)
{
if(year==(2007+i))
{
%>
<option value = "<%=2007+i%>" selected><%=2007+i%> </option>
<%
}else
{
%>
<option value = "<%=2007+i%>"><%=2007+i%> </option>
<%
}
}%>
</select>
年 :
<select size="1" name="em" id="b1" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=12;i++){if(i==month)
{
%>
<option value = "<%=i%>" selected> <%=i%> </option>
<%
}else
{
%>
<option value = "<%=i%>" > <%=i%> </option>
<%
}%>
<%}%>
</select>
月 :
<select size="1" name="ed" id="c1" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=31;i++){if(i==day)
{
%>
<option value = "<%=i%>" selected> <%=i%> </option>
<%
}else
{
%>
<option value = "<%=i%>" > <%=i%> </option>
<%
}%>
<%}%>
</select>
日 </div></td>
</tr>
<tr bgcolor="#EEF8F7">
<td > </td>
</tr>
<tr bgcolor="#EEF8F7">
<td ><table width="80%" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td><div align="center">选中的设备</div></td>
<td> </td>
<td><div align="center">请选择要查询的设备</div></td>
</tr>
<tr>
<td><div align="center">
<select name="A4" size="7" multiple id="A4" style="width:300px" onDblClick="down()">
</select>
</div></td>
<td><p align="center">
<input class="Submit_1" type="button" name="button" id="button" value=" < " onClick="up()">
<p align="center">
<input class="Submit_1" type="button" name="button2" id="button2" value=" > " onClick="down()">
</td>
<td><div align="center">
<select name="A3" size="7" multiple id="A3" style="width:300px" onDblClick="up()">
<option value="<%=ar.getDEVICE_MAC()%>"> <%=ar.getDEVICE_MAC() %> | <%=name%> </option>
</select>
</div>
<table width="100" border="0" align="center" cellpadding="0" cellspacing="10" class="font_1">
<tr>
<td background="<%=url%>/html_temp/button_01.gif" width="80px" height="22px" style="cursor:hand" onClick="tijiao()" ><div align="center" class="font_22" >查询</div></td>
</tr>
</table>
</form>
根据选择的设备mac 和 时间 还有在复选框里选择的端口(c1\c2\c3\c4\c5\c6) 求和... 请高手
在check页面里显示已选端口对应数据库字段值的和,比如复选择的是端口一和端口三,在check页里就显示端口一的和为: 端口三的和为:
页面我已经做好了 效果如下:
代码如下:
----------------------------------------------------------------------------------------------
<%@ page import="com.xx.db.DAO" %>
<scrip>
function CompareDate(d1,d2)
{
return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}
function tijiao()
{var a=document.getElementById("a").value;
var b=document.getElementById("b").value;
var c=document.getElementById("c").value;var a1=document.getElementById("a1").value;var b1=document.getElementById("b1").value;var c1=document.getElementById("c1").value;var current_time = a+"-"+b+"-"+c+" 0:00";
var stop_time = a1+"-"+b1+"-"+c1+" 0:00";if( document.getElementById("dk1").checked==true || document.getElementById("dk2").checked==true || document.getElementById("dk3").checked==true || document.getElementById("dk4").checked==true || document.getElementById("dk5").checked==true || document.getElementById("dk6").checked==true)
{ var obj = document.getElementById("A4"); //取下拉框 选中的值
var macall="";
for (var i=0; i < obj.length; i++)
{
if(i==obj.length-1)
{
macall+=obj.options[i].value;
}else
{
macall+=obj.options[i].value+",";
}
}
document.getElementById("allmac").value=macall;
else
{
alert("至少选中一端口");
}}</script>
<body >
<%
Calendar c=new GregorianCalendar();//新建日期对象
int year=c.get(Calendar.YEAR);//获取年份
int month=c.get(Calendar.MONTH)+1;//获取月份
int day=c.get(Calendar.DATE);//获取日期
String url=request.getContextPath();
%>
<form method="post" action="check.jsp" name="form1">
<input type="hidden" name="fanhui" value="/Action_4.do?action=getmac">
<input type="hidden" name="act" value="device">
<input type="hidden" name="allmac" value="">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="10" class="font_1">
<tr>
<td width="166" rowspan="3"> </td>
<td width="157" rowspan="3"> </td>
<td width="20" height="-4" class="font_1" style="cursor:hand" onClick="filtrate('')" > </td>
<td width="393" rowspan="3"> <div align="left">
<input type="checkbox" name="dk1" id="dk1" value="1" checked>
端口一
<input type="checkbox" name="dk2" id="dk2" value="2" checked>
端口二
<input type="checkbox" name="dk3" id="dk3" value="3" checked>
端口三
<input type="checkbox" name="dk4" id="dk4" value="4" checked>
端口四
<input type="checkbox" name="dk5" id="dk5" value="5" checked>
端口五
<input type="checkbox" name="dk6" id="dk6" value="6" checked>
端口六 </div></td>
</tr>
<tr>
<td height="3" class="font_1" style="cursor:hand" onClick="filtrate('')" > </td>
</tr>
<tr>
<td width="20" height="11" class="font_1" style="cursor:hand" onClick="filtrate('')" > </td>
</tr>
</table>
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0" class="font_1">
<tr>
<td width="12px" ><img src="<%=url%>/html_temp/table_10.gif" width="12" height="16" /></td>
<td background="<%=url%>/html_temp/table_09.gif"></td>
<td width="14px" ><img src="<%=url%>/html_temp/table_08.gif" width="14" height="16" /></td>
</tr>
<tr>
<td background="<%=url%>/html_temp/table_03.gif"></td>
<td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="table_z">
<tr bgcolor="#EEF8F7">
<td > </td>
</tr>
<tr bgcolor="#EEF8F7">
<td ><div align="center">开 始 时 间
<select size="1" name="sy" id="a" style="position: relative;width:100; background:#FFFFFF;">
<%
for(int i=1;i<=40;i++)
{ %>
<option value = "<%=2007+i%>"><%=2007+i%> </option>
<% }%>
</select>
年 :
<select size="1" name="sm" id="b" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=12;i++){%>
<option value = "<%=i%>"> <%=i%> </option>
<%}%>
</select>
月 :
<select size="1" name="sd" id="c" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=31;i++){%>
<option value = "<%=i%>"> <%=i%> </option>
<%}%>
</select>
日 </div></td>
</tr>
<tr bgcolor="#EEF8F7">
<td > </td>
</tr>
<tr bgcolor="#EEF8F7">
<td ><div align="center">结 束 时 间
<select size="1" name="ey" id="a1" style="position: relative;width:100; background:#FFFFFF;">
<%
for(int i=1;i<=40;i++)
{
if(year==(2007+i))
{
%>
<option value = "<%=2007+i%>" selected><%=2007+i%> </option>
<%
}else
{
%>
<option value = "<%=2007+i%>"><%=2007+i%> </option>
<%
}
}%>
</select>
年 :
<select size="1" name="em" id="b1" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=12;i++){if(i==month)
{
%>
<option value = "<%=i%>" selected> <%=i%> </option>
<%
}else
{
%>
<option value = "<%=i%>" > <%=i%> </option>
<%
}%>
<%}%>
</select>
月 :
<select size="1" name="ed" id="c1" style="position: relative;width:100; background:#FFFFFF;">
<%for(int i=1;i<=31;i++){if(i==day)
{
%>
<option value = "<%=i%>" selected> <%=i%> </option>
<%
}else
{
%>
<option value = "<%=i%>" > <%=i%> </option>
<%
}%>
<%}%>
</select>
日 </div></td>
</tr>
<tr bgcolor="#EEF8F7">
<td > </td>
</tr>
<tr bgcolor="#EEF8F7">
<td ><table width="80%" border="0" align="center" cellpadding="0" cellspacing="5">
<tr>
<td><div align="center">选中的设备</div></td>
<td> </td>
<td><div align="center">请选择要查询的设备</div></td>
</tr>
<tr>
<td><div align="center">
<select name="A4" size="7" multiple id="A4" style="width:300px" onDblClick="down()">
</select>
</div></td>
<td><p align="center">
<input class="Submit_1" type="button" name="button" id="button" value=" < " onClick="up()">
<p align="center">
<input class="Submit_1" type="button" name="button2" id="button2" value=" > " onClick="down()">
</td>
<td><div align="center">
<select name="A3" size="7" multiple id="A3" style="width:300px" onDblClick="up()">
<option value="<%=ar.getDEVICE_MAC()%>"> <%=ar.getDEVICE_MAC() %> | <%=name%> </option>
</select>
</div>
<table width="100" border="0" align="center" cellpadding="0" cellspacing="10" class="font_1">
<tr>
<td background="<%=url%>/html_temp/button_01.gif" width="80px" height="22px" style="cursor:hand" onClick="tijiao()" ><div align="center" class="font_22" >查询</div></td>
</tr>
</table>
</form>
个人认为复选框可以把name属性值设为相同,然后根据request.getParamevalues("")获取value值保存在数组中,这样就可以取出你所选中的复选框的值,之后sql部分就简单了