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. MySQL字符串转日期类型

    MySQL字符串转日期类型 select str_to_date('2014-08-20 00:00:00', '%Y-%m-%d %H:%i:%s'); >2014-08-20 00:00:0 ...

  2. 使用“原生”HTML DOM获取input的输入值并显示

    理论基础 HTML <input> value属性.value规定<input>元素的值.value对于不同input类型,用法也不同. 1.对于"button&qu ...

  3. Netty学习之客户端创建

    一.客户端开发时序图 图片来源:Netty权威指南(第2版) 二.Netty客户端开发步骤 使用Netty进行客户端开发主要有以下几个步骤: 1.用户线程创建Bootstrap Bootstrap b ...

  4. Azure开发者任务之六:使用WCF Service Web Role

    在本文中,我们将会在local development fabric上创建一个WCF服务角色,然后在一个控制台应用程序中使用它. WCF服务角色可以让我们创建一个WCF服务,并且把它托管在Window ...

  5. WebApi传参总动员(二)

    上篇,从最简单的string入手.本篇演示了从请求的输入流中获取实体.api: public class ValuesController : ApiController { [HttpPost] p ...

  6. 不要迷恋那些没技术含量的Linux发行版

    昨天悲剧了,重装系统,一个手贱点了替换原系统,分区全给删了,将近三天的工作成果没有了.

  7. u-boot移植总结(四)u-boot-2010.09框架分析

    (一)本次移植是基于FL2440,板子的基本硬件: CPU 型号为S3C2440,基于ARM920T,指令集ARMV4,时钟主频400MHz SDRAM H57V2562GTR-75C 2片*32MB ...

  8. ahjesus 获取当前方法被调用执行的具体位置,包括命名空间和方法

    MethodBase method = ).GetMethod(); string ahjesus = method.ReflectedType.FullName + "." + ...

  9. 使用正则表达式获取Sql查询语句各项(表名、字段、条件、排序)

    string text = "select * from [admin] where aa=1 and cc='b' order by aa desc "; Regex reg = ...

  10. has_many :through VS has_and_belongs_to_many

    user role has_and_belongs_to_many role.destroy:  关联表user_roles先删除记录,再role删除. has_many :through user. ...