beans包和jdbc包代码不放了,麻烦

Service.java:

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 dbconnection;
    private Statement st,st1,st2;
    private ResultSet rs,rs1,rs2;
    private String sql,sql1,sql2;
    private List list;
    private Profit pf;
    
    public List getProfit(){
        list=new ArrayList();
        dbconnection=JdbcConn.getCon();
        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 t_goods g,t_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("costPrice"));
                pf.setGoodsId(rs.getInt("goodsId"));
                
                temp=0;
                temp=pf.getSellingPrice()-pf.getCostPrice();
                
                sql1="SELECT SUM(t.TRADING_NUMBER) sunNum FROM t_trading t WHERE t.TRADING_GOODS_ID="+pf.getGoodsId();
                rs1=st1.executeQuery(sql1);
                while(rs1.next()){
                    pf.setTradingNum(rs1.getInt("sunNum"));
                }
                
                pf.setProfit(temp*pf.getTradingNum());
                sql2="SELECT COUNT(t.TRADING_GOODS_ID) times FROM t_trading t WHERE t.TRADING_GOODS_ID="+pf.getGoodsId();
                rs2=st2.executeQuery(sql2);
                while(rs2.next()){
                    pf.setTimes(rs2.getInt("times"));
                }
                
                list.add(pf);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        
        return list;
    }
}

ShowReport.java:

package servlet;

import java.io.IOException;
import java.io.PrintWriter;
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;

public class ShowReport extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        List list;
        Service service=new Service();
        list=service.getProfit();
        
        request.getSession().setAttribute("PROFIT",list);
        response.sendRedirect("index.jsp");
    }

@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request, response);
    }
    
    
}

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>
    <style type="text/css">
    table.hovertable{
        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;
          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);
                      temp1+=pf.getTradingNum();
                      temp2+=pf.getTimes();
                      temp3+=pf.getProfit();
                      %>
                          <tr onmouseover="this.style.backgroundColor='#ffff66';"
                              onmouseout="this.style.backgroundColor='#d4e3e5';">
                              <td><%=temp+=1 %></td>
                              <td><%=pf.getGoodsName() %></td>
                              <td><%=pf.getTradingNum() %></td>
                              <td><%=pf.getTimes() %></td>
                              <td><%=pf.getProfit() %></td>
                          </tr>
                      <%
                  }%>
                          <tr onmouseover="this.style.backgroundColor='#ffff66';"
                              onmouseout="this.style.backgroundColor='#d4e3e5';">
                              <td colspan="2">合计</td>
                              <td><%=temp1 %></td>
                              <td><%=temp2 %></td>
                              <td><%=temp3 %></td>
                          </tr>
                  <%
              }
          }
   %>
   </table>
  </body>
</html>

利用jsp和servlet,MySQL实现简易报表的更多相关文章

  1. jsp+servlet+mysql 实现简单的银行登录转账功能

    jsp+servlet+mysql 实现简单的银行登录转账功能 [前期的准备] html(登录界面),servlet(处理业务逻辑),jsp(主要实现界面),mysql(实现与数据库的简单的交互)先从 ...

  2. SpringMVC内容略多 有用 熟悉基于JSP和Servlet的Java Web开发,对Servlet和JSP的工作原理和生命周期有深入了解,熟练的使用JSTL和EL编写无脚本动态页面,有使用监听器、过滤器等Web组件以及MVC架构模式进行Java Web项目开发的经验。

    熟悉基于JSP和Servlet的Java Web开发,对Servlet和JSP的工作原理和生命周期有深入了解,熟练的使用JSTL和EL编写无脚本动态页面,有使用监听器.过滤器等Web组件以及MVC架构 ...

  3. jsp、servlet笔记

    1.init    初始化Jsp&Servlet方法   destroy 销毁Jsp&Servlet之前的方法   service 对用户请求生成响应的方法2.Jsp文件必须在jsp服 ...

  4. JSP/Servlet开发——第七章 Servel基础

    1.Servlet简介: ●Servlet是一个符合特定规范的 JAVA 程序 , 是一个基于JAVA技术的Web组件. ●Servlet允许在服务器端,由Servlet容器所管理,用于处理客户端请求 ...

  5. java语言体系的技术简介之JSP、Servlet、JDBC、JavaBean(Application)

    转自:https://zhangkunnan.iteye.com/blog/2040462 前言 Java语言 Java语言体系比较庞大,包括多个模块.从WEB项目应用角度讲有JSP.Servlet. ...

  6. jsp与servlet(转)

    一.基本概念 1.1 Servlet Servlet是一种服务器端的Java应用程序,具有独立于平台和协议的特性,可以生成动态的Web页面.它担当客户请求(Web浏览器或其他HTTP客户程序)与服务器 ...

  7. JSP和Servlet的中文乱码处理

    JSP和Servlet的中文乱码处理 前几天学习了JSP和Servlet中有关中文乱码的一些问题,写成了博客,今天进行更新一下.应该是可以解决日常的乱码问题了.现在作以下总结希望对需要的人有所帮助.我 ...

  8. Jsp与servlet本质上的区别

    1.jsp经编译后就变成了Servlet.(JSP的本质就是Servlet,JVM只能识别java的类,不能识别JSP的代码,Web容器将JSP的代码编译成JVM能够识别的java类)2.jsp更擅长 ...

  9. Jsp与servlet的区别 1

     Jsp与servlet的区别 2011-12-09 16:27:47 分类: Java 1.jsp经编译后就变成了Servlet.(JSP的本质就是Servlet,JVM只能识别java的类,不能识 ...

随机推荐

  1. Scrum项目1.0

    1) N (Need 需求) 面向小学生 2) A (Approach 做法) 3) B (Benefit  好处) 让小学生以游戏的方式进行学习 4) C (Competitors 竞争) 减少练习 ...

  2. 用Qt写软件系列一:QCacheViewer(浏览器缓存查看器)

    介绍 Cache技术广泛应用于计算机行业的软硬件领域.该技术既是人们对新技术探讨的结果,也是对当前软硬件计算能力的一种妥协.在浏览器中使用cache技术,可以大幅度提高web页面的响应速度,降低数据传 ...

  3. android 获取当前位置

    1. Android开发位置感知应用程序方式:1. GPS 定位     精确度高,仅适用于户外,严重消耗电量.如果手机内置GPS接受模块,即使手机处于信号盲区,依然可以获取位置信息. 2. NETW ...

  4. C#设计模式——装饰者模式(Decorator Pattern)

    一.例子在软件开发中,我们往往会想要给某一类对象增加不同的功能.比如要给汽车增加ESP.天窗或者定速巡航.如果利用继承来实现,就需要定义无数的类,Car,ESPCar,CCSCar,SunRoofCa ...

  5. 【WP8】扩展CM的WindowManager

    14-09-09更新:修复AppBar冲突bug 关于WindowManager,一直都很想写一篇博客分享一下,一直在忙别的,今天抽空把这个分享一下 在弹窗在移动开发是一个很常见的交互,很多时候我们都 ...

  6. 20161119微信小程序初识

    Tritonal ft. Angel Taylor - Getaway [Official Lyric Video]

  7. 进入IT企业必读的200个.NET面试题

    点击打开链接 点击打开链接 版权声明:本文为博主原创文章,未经博主允许不得转载.

  8. 小型app开发的思路

    前提: 1. 性能不是最重要: 2. 人手少: 3. 速度要快: 结论: 1. 混合式 2. 减少app的复杂程度 3. 追求性能 (博客,尽量让自己每天写一点,短一点都可以)

  9. QT分页控件,开源,供大家使用

    下载地址:http://files.cnblogs.com/dragonsuc/qt5.rar

  10. 怎样让js循环重复执行过程

    setInterval(function(){ cc();},60000);setInterval是每隔一分钟就执行一次方法体,主要特点是循环不断的执行.而setTimeout是执行一次就不会继续执行 ...