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. Spring基础——在 IOC 容器中 Bean 之间的关系

    一.在 Spring IOC 容器中 Bean 之间存在继承和依赖关系. 需要注意的是,这个继承和依赖指的是 bean 的配置之间的关系,而不是指实际意义上类与类之间的继承与依赖,它们不是一个概念. ...

  2. MyEclipse搭建SSM框架(Spring+MyBatis+SpringMVC)

    待写. 参考网址 http://www.cnblogs.com/Joetao/articles/4544572.html http://www.cnblogs.com/verlen11/p/53497 ...

  3. 组合数(Lucas定理) + 快速幂 --- HDU 5226 Tom and matrix

    Tom and matrix Problem's Link:   http://acm.hdu.edu.cn/showproblem.php?pid=5226 Mean: 题意很简单,略. analy ...

  4. [转]easyui datagrid 批量编辑和提交

    web前台主要代码: <script type="text/javascript"> $(function() { var $dg = $("#dg" ...

  5. 整理的有用的一些EF的CommonDAL小封装

    CommonDAL封装: using System; using System.Collections.Generic; using System.Data.Entity; using System. ...

  6. JMS学习(四) Selector详解

    一.前言 在掌握了消息的结构之后,我们接下来看一下JMS的一个重要功能:选择器.有些时候,作为消费者只希望处理自己感兴趣的消息.如果某个消息只有一个消费者,我们可以在让该客户端根据规则来处理自己感兴趣 ...

  7. IE Unknown runtime error

    1. 在函数中使用原生的js的时候,有时在IE下会出现Unknown runtime error 火狐下正常 2. 解决办法, 将原生js改成jquery处理兼容问题 document.getElem ...

  8. LinkedList的实现源码分析

    LinkedList 以双向链表实现.链表无容量限制,但双向链表本身使用了更多空间,也需要额外的链表指针操作. 按下标访问元素--get(i)/set(i,e) 要悲剧的遍历链表将指针移动到位(如果i ...

  9. Introduction to ASP.NET 5

    ASP.NET 5 is a significant redesign of ASP.NET. This topic introduces the new concepts in ASP.NET 5 ...

  10. ThoughtWorks.QRCode生成二维码

    首先引用需要的dll,此处使用的是ThoughtWorks.QRCode.dll,网上可以找到对应的,此处也有一份,点击下载 http://files.cnblogs.com/files/ives/T ...