我的 jsp 中有一个包含数据库中所有用户的下拉列表。当我选择一个用户时,我可以获得相应结果的详细信息,但是当我点击全部时,它应该单独给出总数。下面是我用来单独获取的代码。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="DBCon.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
</head>
<body><form name="Reports" method="post" action="DropDown.jsp"><table><tr>
<td>From</td><td><input type="text" id="from" name="from"></td></tr>
<tr><td>To</td><td><input type="text" id="to" name="to"></td></tr>
<tr><td>Select user:</td><td><select name="user" id="user">
<option value="">Select User</option>
<%
try{
ps=con.prepareStatement("select substr(sys_connect_by_path(userid,','),2) userid from (select rownum rowno,'''' || userid || '''' userid from users where rownum < 4)where connect_by_isleaf = 1 connect by prior rowno = rowno - 1 start with rowno = 1");
rs=ps.executeQuery();
while(rs.next()){
%>
<option value="<%String user2=rs.getString(1);out.println(user2);%>">All</option>
<%
}
}
catch(Exception e)
{
out.println(e);
}
%>
<%
try{
ps=con.prepareStatement("Select Distinct Specialist from Scope1");
rs=ps.executeQuery();
while(rs.next()){
%>
<option value="'<%String user1=rs.getString(1);out.print(user1);%>'"><%out.print(user1);%></option>
<%
}
out.println("<select>");
}
catch(Exception e)
{
out.println(e);
}
%>
</select></td></tr>
<tr><td>
Select Type:</td><td><select name="type" id="type">
<option value="">Select Type</option>
<option value="'Updates','Multibases','DAIS','Acds','Legis','LegAll'">All</option>
<%
try{
ps=con.prepareStatement("Select Distinct type from Scope1");
rs=ps.executeQuery();
while(rs.next()){
%>
<option value="'<%String type1=rs.getString(1).trim();out.print(type1);%>'"><%out.println(type1.trim());%></option>
<%
}
out.println("<Select>");
}
catch(Exception e)
{
out.println(e);
}
%>
</select></td></tr>
<tr><td><input type="submit" value="Generate" id="sub1" name="sub1"></td></tr>
</table> </form> </body>
</html>
得到的结果如下。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="DBCon.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body><table>
<%
String a=request.getParameter("type").trim();
String b=request.getParameter("user").trim();
String c=request.getParameter("from").trim();
String d=request.getParameter("to").trim();
try{%>
<tr><b><%=b%></b></tr><%
//String sql=("SELECT type, SUM(Update_Count) FROM Scope1 where type in ("+a+") and Specialist in ("+b+") and (RECVD_DATE >='"+c+"' and RECVD_DATE <='"+d+"') group by type");
//out.print(sql);
ps1=con.prepareStatement("SELECT type, SUM(Update_Count) FROM Scope1 where type in ("+a+") and Specialist in ("+b+") and (RECVD_DATE >='"+c+"' and RECVD_DATE <='"+d+"') group by type");
rs1=ps1.executeQuery();
while(rs1.next())
{
%>
<tr><td><b><%=rs1.getString(1)%></b></td><td><%=rs1.getString(2)%></td></tr>
<%
}
}
catch(Exception e)
{
out.println(e);
}
%>
</table> </body>
</html>
谢谢