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. 计数排序 + 线段树优化 --- Codeforces 558E : A Simple Task

    E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作, ...

  2. 在aspx怎么引用public string getPicurl(string picurl)?

    刚才在论坛上看到一帖: Insus.NET尝试做了一下,直接使用一个Img标签是无法实现.因为函数中返回的即是一个img html标签,因此在aspx页再不能使用Img了. 现在可以回到网友的问题,那 ...

  3. C#验证身份证号码

    一.18位的身份证号码 如:130429####%%%%00781.1~6位为地区代码,其中1.2位数为各省级政府的代码,3.4位数为地.市级政府的代码,5.6位数为县.区级政府代码.如13(河北省) ...

  4. visual studio 2013 配置开发环境

    https://www.visualstudio.com/explore/xamarin-vs http://sourceforge.net/projects/easyeclipse/files/?s ...

  5. sql 两列相加存到另一列

    假设表table1有a.b两个列,想生成另一个列为a列值+b列值计算列添加语句如下ALTER TABLE table1ADD c AS a+b

  6. [Eclipse] - 解决导入flask模块出现的Unresolved Import flask问题

    http://www.cnblogs.com/mizhon/p/4242073.html [Eclipse] - 解决导入flask模块出现的Unresolved Import flask问题 最近想 ...

  7. Powerbuilder编写身份证校验码

    public function boolean of_calc_cardid_verifycode (string as_cardid, ref string as_verifycode); /* 计 ...

  8. Html==>>一些经典

    1.CSS overflow 属性 2.<input>标签 <input> 标签用于搜集用户信息. 1 type属性 根据不同的 type 属性值,输入字段拥有很多种形式.可以 ...

  9. EntityFramework4.1开发

    常见问题大概为这几个 一.ef4.1 codeFirst 修改表结构 增加字段等 EF code first需要重新生成库导致数据丢失的问题. 二.ef4.1 没有了edmx等复杂的东西 变得简单 干 ...

  10. andriod 获取电池的信息

    <?xml version="1.0"?> <LinearLayout android:orientation="vertical" andr ...