📄 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 + -