这是我的源码 为什么运行不了(顺便分享一下源码)
四个实体类就不贴了
//JDBC类下的连接
package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class jdbcConn {
private static String URL="jdbc:mysql://localhost:3306/report_form";
private static String user="root";
private static String password="123456";
public static Connection conn;
public static void main(String[] args) throws SQLException {
jdbcConn jdbc = new jdbcConn();
System.out.println(jdbc.getConnection().isClosed());
}
public static Connection getConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(URL, user, password);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
}
//servlet类
package servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.Service;
/**
* Servlet implementation class Report
*/
public class Report extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Report() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Service serv = new Service();
List list = serv.getProfit();
request.getSession().setAttribute("REPORT", list);
response.sendRedirect("index.jsp");
}
}
//service类
package service;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import beans.Profit;
import jdbc.jdbcConn;
public class Service {
private Connection jdbcconn;
private Statement st,st2,st3;
private ResultSet rs,rs2,rs3;
private String sql,sql2,sql3;
private List list;
private Profit pf;
public List getProfit(){
list = new ArrayList();
jdbcconn = jdbcConn.getConnection();
try {
st = jdbcconn.createStatement();
st2 = jdbcconn.createStatement();
sql="SELECT g.name gName, g.cost_price gCost,"
+ "g.selling_price gSelling,g.id gId "
+ "FROM goods g ,trading t "
+ "WHERE g.id =t.goods_id "
+ "GROUP BY g.name , g.cost_price ,g.selling_price ,g.id";
rs = st.executeQuery(sql);
int temp;
while(rs.next()){
pf = new Profit();
pf.setGoods_name(rs.getString("gName"));
pf.setCostPrice(rs.getInt("gCost"));
pf.setSellingPrice(rs.getInt("gSelling"));
pf.setGoods_id(rs.getInt("gId"));
temp = 0;
temp = pf.getSellingPrice() - pf.getCostPrice();
//得到单品交易总量
sql2="SELECT SUM(t.number) sumNum FROM trading t WHERE t.goods_id = "
+pf.getGoods_id();
rs2 = st2.executeQuery(sql2);
while (rs2.next()){
pf.setTradingNum(rs2.getInt("sumNum"));
}
//利润汇总
pf.setProfit(temp*pf.getTradingNum());
//得到time订单数量
sql3="SELECT count(t.number) countNum FROM trading t WHERE t.goods_id = "
+pf.getGoods_id();
rs3 = st3.executeQuery(sql2);
while (rs3.next()){
pf.setTime(rs3.getInt("countNum"));
}
//加入到List中
list.add(pf);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
}
//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">
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.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>
<br>
<from action="Report" method="post">
<input type="submit" value="生成报表"/><br>
</from>
<table class="hovertable">
<!-- 生成表头 -->
<tr>
<th colspan="5" align="center">利润表</th>
</tr>
<tr>
<th>序号</th>
<th>商品名称</th>
<th>卖出交易</th>
<th>交易笔数</th>
<th>盈利额</th>
</tr>
<%
List list = null;
if(session.getAttribute("REPORT") != null){
//得到数据表
list = (List) session.getAttribute("REPORT");
if(list.size()>0){
int temp1 =0;
int temp2 =0;
int temp3 =0;
int temp4 =0;
Profit pf;
for(int i =0;i<list.size();i++){
pf = new Profit();
pf = (Profit) list.get(i);
temp2+=pf.getTradingNum();
temp3+=pf.getTime();
temp4+=pf.getProfit();
%>
<tr onmouseover="this.style.backgroundColor='#ffff66';"
onmouseout="this.style.backgroundColor='#d4e3e5'">
<td><%=temp1++ %></td>
<td><%=pf.getGoods_name() %></td>
<td><%=pf.getTradingNum() %></td>
<td><%=pf.getTime() %></td>
<td><%=pf.getProfit() %></td>
</tr>
<%
}%>
<tr onmouseover="this.style.backgroundColor='#ffff66';"
onmouseout="this.style.backgroundColor='#d4e3e5'">
<td colspan="2">合计</td>
<td><%=temp2 %></td>
<td><%=temp3 %></td>
<td><%=temp4 %></td>
</tr>
<%}
}
%>
</table>
</body>
</html>为什么出错完全没反应 index.jsp页面只出现表头 不能转跳