为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我这里没有显示鼠标的悬停可改变页面颜色,以为什么我加载了mysql的jar文件还是不能显示报表的内容呢?

首先是index.jsp

<%@ page language="java" import="java.util.*,beans.*"

pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<base href="<%=basePath%>">

<title>原生态java环境生成报表</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">


<!-- CSS -->

<style type="text/css">

table.hovertable {

font-family: verdana, arial, sans-serif;

font-size: 13px;

color: #333333;

border-width: 1px;

border-color: #999999;

border-collapse: collapse;

}


table.hovertable th {

background-color: #c3dde0;

border-width: 1px;

padding: 8px;

border-style: solid;

border-color: #a9c6c9;

}


table.hovertable tr {

background-color: #d4e3e5;

}


table.hovertable td {

border-width: 1px;

padding: 8px;

border-style: solid;

border-color: #a9c6c9;

}

</style>

</head>

<body>

<form action="ShowReport" method="post">

<input type="submit" value="生成报表">

</form>

<table class="hovertable">

<tr>

<th colspan="5">利润表</th>

</tr>

<tr>

<th>序号</th>

<th>商品名称</th>

<th>卖出数量</th>

<th>交易笔数</th>

<th>盈利额</th>

</tr>

<%

List list = null;//初始化一个List


if (session.getAttribute("PROFIT") != null) {

list = (List) session.getAttribute("PROFIT");

if (list.size() > 0) {

int temp = 0;

int temp1 = 0;

int temp2 = 0;

int temp3 = 0;

Profit pf;

for (int i = 0; i < list.size(); i++) {

pf = new Profit();

pf = (Profit) list.get(i);

%>

<tr onmouseover="this.style.backgroundColor='#ffff66';"

onmouseout="this.style.backgroundColor='#d4e3e5';">

<td><%=temp+=1%></td>

<td><%=pf.getGoodsName()%></td>

<td><%=pf.getTradingNumber()%></td>

<td><%=pf.getTimes()%></td>

<td><%=pf.getProfit()%></td>

</tr>

<%

}

}

}

%>

</table>


</body>

</html>

然后是我的JdbcConn类

public class JdbcConn {

   private static String url="jdbc:mysql://127.0.0.1:3306/TestReport";

   private static String user = "root";

   private static String password = "123";

   public static Connection conn;

   public static PreparedStatement ps;

   public static ResultSet rs;

   public static Statement st;

   

   public static Connection getConnection(){

   //1.首先我们要初始化驱动包

   try {

Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(url,user,password);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

   return conn;

   }

}

这是我的Service类

public class Service {

private Connection dbConnection;

    private Statement st,st1,st2;

    private ResultSet rs,rs1,rs2;

    private String sql;

    private List list;

    private Profit pf;

    

    public List getProfit(){

    list = new ArrayList();

    dbConnection = JdbcConn.getConnection();

    try {

st = (Statement)dbConnection.createStatement();

st1 = (Statement)dbConnection.createStatement();

st2 = (Statement)dbConnection.createStatement();

sql="select g.goods_name goodsName,g.selling_price selling,g.cost_price costPrice,g.goods_id goodsId"

+ "from goods g,trading t"

+ "where t.trading_goods_id=g.goods_id"

+ "group by g.goods_name;";

rs = st.executeQuery(sql);

int temp;

while(rs.next()){

pf = new Profit();

pf.setGoodsName(rs.getString("goodsName"));

pf.setSellingPrice(rs.getInt("selling"));

pf.setCostPrice(rs.getInt("selling"));

pf.setGoodsId(rs.getInt("goodsId"));

temp=0;

    temp=pf.getSellingPrice()-pf.getCostPrice();//单品利润

    

    sql="select sum(t.trading_number) sumNum from trading t where t.trading_goods_id= "+pf.getGoodsId();

    rs1=st1.executeQuery(sql);

    while(rs1.next()){

    pf.setTradingNumber(rs1.getInt("sumNum"));//这里获得了卖出的数量

    }

    pf.setProfit(temp*pf.getTradingNumber());//总利润=单品利润*卖出的数量

    sql="select count(t.trading_id) times from trading t where t.trading_goods_id= "+pf.getGoodsId();

    rs2=st2.executeQuery(sql);

    while(rs2.next()){

    pf.setTradingNumber(rs1.getInt("times"));//这里获得了卖出的数量

    }

    list.add(pf);//那我们取得的结果集pf(利润)放到List集合里

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

    return list;

    }

}

https://img1.sycdn.imooc.com//5cd3a0c2000104d803990234.jpg

正在回答

1 回答

这样直接看代码看起来比较麻烦。。你需要把控制台报的错发出来。。

如果是数据库没连上,那你可以试一试在数据库连接类里面写一个main函数先试试自己的连接是否有问题。。当然按照视频里这样jar包,应该是没有问题。。如果是你自己jar的包,还容易出现找不到jar包。

至于鼠标悬停,因为你连数据都没有你怎么看它有没有悬停变颜色。。你的表头也就是th是没有设置悬停样式。。至于显示的数据才有悬停样式!!

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为什么我这里没有显示鼠标的悬停可改变页面颜色,以为什么我加载了mysql的jar文件还是不能显示报表的内容呢?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信