public?class?Servlet?extends?HttpServlet?{
????public?void?init()?throws?ServletException{}
????public?void?destroy(){}
????public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response){
????????doPost(request,response);
????}
????public?void?doPost(HttpServletRequest?request,HttpServletResponse?response){
????????Service?service?=?new?Service();
????????try?{
????????????List<Profit>?list?=?service.getProfitList();
????????????request.getSession().setAttribute("ProfitList",list);
????????????response.sendRedirect("index.jsp");
????????}?catch?(Exception?e)?{
????????????e.printStackTrace();
????????}
????}
}
<%@?page?import="java.util.List"?%>
<%@?page?import="com.beans.Profit"?%>
<%@?page?contentType="text/html;charset=UTF-8"?language="java"?%>
<html>
??<head>
????<title>Java原生態(tài)生成報(bào)表</title>
??</head>
??<body>
??<!--?js格式待做?-->
??<table?class=""?>
????<form?action=""?method="post">
??????<tr?><td?colspan="7">商品利潤(rùn)表</td></tr>
??????<tr>
????????<th>商品ID</th>
????????<th>商品名</th>
????????<th>成本價(jià)</th>
????????<th>銷售價(jià)</th>
????????<th>商品總利潤(rùn)</th>
????????<th>交易次數(shù)</th>
????????<th>交易總數(shù)</th>
??????</tr>
??<%
????List<Profit>?list?=?null;
????int?temp?=?0;
????int?temp1?=?0;
????int?temp2?=?0;
????int?temp3?=?0;
????int?temp4?=?0;
????int?temp5?=?0;
????if?(session.getAttribute("ProfitList")!=null){
????if?(list==null)?{
??????list?=?(List<Profit>)?session.getAttribute("ProfitList");
????}
????for?(int?i=0;i<list.size();i++){
??????Profit?p?=?list.get(i);
??????if?(p!=null){
??????????temp1?+=?p.getCostPrice();
??????????temp2?+=?p.getSellingPrice();
??????????temp3?+=?p.getPrfit();
??????????temp4?+=?p.getTimes();
??????????temp5?+=?p.getTradingNumber();
??%>
??????<tr>
????????<td><%=temp++%></td>
????????<td><%=p.getGoodsId()%></td>
????????<td><%=p.getGoodsName()%></td>
????????<td><%=p.getCostPrice()%></td>
????????<td><%=p.getSellingPrice()%></td>
????????<td><%=p.getPrfit()%></td>
????????<td><%=p.getTimes()%></td>
????????<td><%=p.getTradingNumber()%></td>
??????</tr>
??????<%
????????}
????????%>
??????<tr>
????????<td?colspan="2">合計(jì)</td>
????????<td><%=temp1%></td>
????????<td><%=temp2%></td>
????????<td><%=temp3%></td>
????????<td><%=temp4%></td>
????????<td><%=temp5%></td>
??????</tr>
??????<%
??????????}
????????}
??????%>
????</form>
??</table>
??</body>
</html>
2017-10-07
你的合計(jì)在for循環(huán)里 ,放外面試試。