?? statistics.jsp
字號:
<%-- 這個JSP腳本是用來統計圖書信息的 --%>
<%@ page language="java"%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page errorPage="errorpage.jsp" %>
<%@ page import="java.sql.*" %>
<jsp:useBean id="DBexecuteBean" scope="page" class="bookSearchOrderBean.DBexecuteBean"/> <%-- 調用JavaBean --%>
<html>
<head>
<title>網上圖書信息檢索和訂購</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.TableLine { border: #6666FF; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px}
-->
</style>
</head>
<%
String islogin = null;
Cookie[] bookcookie = request.getCookies();
/* 首先驗證訪問者是否已經登錄 */
if(bookcookie != null)
{
for(int j = 0;j < bookcookie.length;j++)
{
if(bookcookie[j].getName().equals("hadlogin"))
{
islogin = bookcookie[j].getValue();
}
}
}
if((islogin == null) || (!(islogin.equals("1"))))
{
throw new Exception("你還沒有登錄,請先登錄!");
}
%>
<body bgcolor="#FFFFFF" link="#6666FF" vlink="#6666FF" alink="#6666FF">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="TableLine">
<tr>
<td height="158">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td height="2">
<div align="center"><font color="#6666FF" size="5" face="華文新魏"><font size="+3"><b><font size="6">圖書信息分類統計</font></b></font></font></div>
</td>
</tr>
<tr>
<td height="2"> </td>
</tr>
<tr>
<td height="66">
<table width="80%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="22%">
<div align="center"><b><font size="3">統計科目</font></b></div>
</td>
<td width="20%">
<div align="center"><b><font size="3">二級分類</font></b></div>
</td>
<td width="29%">
<div align="center"><b><font size="3">數量匯總(本)</font></b></div>
</td>
<td width="29%">
<div align="center"><b><font size="3">價格匯總(元)</font></b></div>
</td>
</tr>
<tr>
<td colspan="4" height="2">
<div align="center">
<hr>
</div>
</td>
</tr>
<%
/* 利用JavaBean從數據庫中找出分類匯總的信息 */
String statistic_type = null;
String statistic_booktype = null;
int totalcounts = -1;
double totalprices = 0;
boolean flag = false;
String sSQLCmd = "select '按類別統計',type,count(bookname),sum(Price) as totalprices from booklist group by type order by totalprices";
ResultSet rset = DBexecuteBean.getTableRecords(sSQLCmd); //調用Bean中的getTableRecords()方法進行身份驗證
while(rset.next())
{
statistic_type = rset.getString(1);
statistic_booktype = rset.getString(2);
totalcounts = rset.getInt(3);
totalprices = rset.getDouble(4);
out.println("<tr>");
if(flag == true)
out.println("<td width=\"22%\"><div align=\"center\"> </div></td>");
else
out.println("<td width=\"22%\"><div align=\"center\">" + statistic_type + "</div></td>");
out.println("<td width=\"22%\"><div align=\"center\">" + statistic_booktype + "</div></td>");
out.println("<td width=\"22%\"><div align=\"center\">" + totalcounts + "</div></td>");
out.println("<td width=\"22%\"><div align=\"center\">" + totalprices + "</div></td>");
out.println("</tr>");
flag = true;
}
%>
<tr>
<td colspan="4">
<div align="center"><font face="Times New Roman, Times, serif">- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -</font></div>
</td>
</tr>
<%
totalcounts = -1;
totalprices = 0;
sSQLCmd = "select count(bookname),sum(Price) from booklist";
rset = DBexecuteBean.getTableRecords(sSQLCmd);
while(rset.next())
{
totalcounts = rset.getInt(1);
totalprices = rset.getDouble(2);
totalprices = (double)((int)(totalprices * 100) / 100.0);
out.println("<tr>");
out.println("<td width=\"22%\"><div align=\"center\">總 計</div></td>");
out.println("<td width=\"22%\"><div align=\"center\">----</div></td>");
out.println("<td width=\"22%\"><div align=\"center\">" + totalcounts + "</div></td>");
out.println("<td width=\"22%\"><div align=\"center\">" + totalprices + "</div></td>");
out.println("</tr>");
}
%>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -