[关闭]
@murph 2017-05-13T11:36:42.000000Z 字数 6973 阅读 518

使用JSP+Servlet技术生成报表

JSP+servlet


简介:报表就是用表格、图表等格式来动态显示数据。本课程是Java Web的案例课程,主要关注于用表格形式来显示数据。主要内容包括报表的基础知识,报表实现原理和核心技术,以及如何使用JSP+Servlet技术来生成报表。

课程须知
学习本课程需要具备JSP和Servlet的基础知识。需要注意的是本课程中使用的是Oracle数据库,但使用MySql数据库也是可以的。
你能学到什么?
1、使用JSP+Sevlet实现报表
2、掌握如何使用MVC模型进行程序开发

第一章:概述

1.1 学习目标

什么是报表?

报表生成的关键要素?
学习目标
- Ⅰ 后台数据抽取
- Ⅱ 数据项逻辑运算
- Ⅲ 前台表格展示

报表在项目中的地位?

  1. 面向管理层和决策层;
  2. 充分显示系统数据价值;

统计信息的特征?

  1. 数量型
  2. 综合性

报表的几种常见形式

  1. 普通二维报表
    image_1bftbr3nohtq1j1m1nas1h13n2t9.png-166kB
  2. 普通二维图表
    image_1bftbspb41fe933rcog16lsea2m.png-421.2kB
  3. 嵌入式组合报表
    image_1bftbtudf5tjg6b19hd1hp91tqk13.png-259.9kB

学习目标

  1. 普通报表的实现

1.2 学习内容

核心技术分析:

  1. 报表生成基本原理
  2. 核心技术点分析
  3. 核心功能实现所需的技术依赖

相关技术--无框架报表生成:

  1. 实现报表输出的准备工作
  2. 报表数据的组织(数据库语言层面)
  3. 原始数据的组装整理
  4. 报表的前台表格展现

第二章:相关技术

2.1 报表生成原理及核心技术点讲解

三个疑问?

  1. 抽取什么数据
  2. 如何抽取数据
  3. 抽取数据后如何做

后台数据抽取
image_1bftc967st1u1s0r1t0119na1ttc1t.png-269kB
数据项逻辑运算
image_1bftcgrdu17jiopt1h1q13l7atu2a.png-295.4kB
前台展示
image_1bftcibkl17g77vkoc1trdv0r2n.png-139.7kB

2.2 核心技术依赖

后台数据抽取
image_1bftcq2vg1c05a0g1hqc1f0qr3e34.png-449.3kB
数据项逻辑运算
image_1bftcstm31h3t196i1eln1e371o0d3h.png-380.5kB
前台展示
image_1bftcuf5ukerbhu1q99sim1p8o3u.png-172.8kB

第三章:报表实现

(原生态JAVA生成报表实例讲解)

3.1 需求概述

实例讲解:案例描述
一家经营数码产品的网店需要一张报表来分析经营情况;
利润表
image_1bftd4d1p1c3116am1nf71suu6u4b.png-254.9kB

案例数据库结构
(数据库共三张表)

3.2 数据模型建立

效果图
image_1bftdcaav1fdhq4u18k1v5414pc5v.png-175.3kB

  1. 新建web工程文件 命名为:TestReport
  2. 首先建立包
    image_1bftf1do71a9rl4ovb15en13id6c.png-23.6kB
    (关于MVC、架构和包的命名:
    浅谈Javaweb经典三层架构和MVC框架模式
    三层架构和MVC不是一个事
    Javaweb或javaEE完整项目名及包名、资源名命名规则
    web及servlet处理的,
    service业务逻辑处理的,
    dao数据库操作的,
    entity实体类

3.创建模型

  1. package beans;
  2. /**
  3. *
  4. * @author Wangqinggang
  5. * @version 1.0.0
  6. * @since
  7. * 创建时间:2017年5月12日
  8. * 功能描述:
  9. * 官方网站:www.study821.com
  10. * 邮箱地址:599255294@qq.com
  11. */
  12. public class Goods {
  13. //商品Id
  14. private int goodsId;
  15. //商品名称
  16. private String goodsName;
  17. //成本价
  18. private String costPrice;
  19. //售价
  20. private String sellingPrice;
  21. //制造商
  22. private String manufacturer;
  23. /**
  24. * @return the goodsId
  25. */
  26. public int getGoodsId() {
  27. return goodsId;
  28. }
  29. /**
  30. * @param goodsId the goodsId to set
  31. */
  32. public void setGoodsId(int goodsId) {
  33. this.goodsId = goodsId;
  34. }
  35. /**
  36. * @return the goodsName
  37. */
  38. public String getGoodsName() {
  39. return goodsName;
  40. }
  41. /**
  42. * @param goodsName the goodsName to set
  43. */
  44. public void setGoodsName(String goodsName) {
  45. this.goodsName = goodsName;
  46. }
  47. /**
  48. * @return the costPrice
  49. */
  50. public String getCostPrice() {
  51. return costPrice;
  52. }
  53. /**
  54. * @param costPrice the costPrice to set
  55. */
  56. public void setCostPrice(String costPrice) {
  57. this.costPrice = costPrice;
  58. }
  59. /**
  60. * @return the sellingPrice
  61. */
  62. public String getSellingPrice() {
  63. return sellingPrice;
  64. }
  65. /**
  66. * @param sellingPrice the sellingPrice to set
  67. */
  68. public void setSellingPrice(String sellingPrice) {
  69. this.sellingPrice = sellingPrice;
  70. }
  71. /**
  72. * @return the manufacturer
  73. */
  74. public String getManufacturer() {
  75. return manufacturer;
  76. }
  77. /**
  78. * @param manufacturer the manufacturer to set
  79. */
  80. public void setManufacturer(String manufacturer) {
  81. this.manufacturer = manufacturer;
  82. }
  83. }
  1. /**
  2. * Users.java
  3. * Version 1.0.0
  4. * Created on 2017年5月12日
  5. * Copyright Wangqingang
  6. *
  7. */
  8. package beans;
  9. /**
  10. * @author Wangqinggang
  11. * @version 1.0.0
  12. * @since
  13. * 创建时间:2017年5月12日
  14. * 功能描述:
  15. * 官方网站:www.study821.com
  16. * 邮箱地址:599255294@qq.com
  17. */
  18. public class Users {
  19. //卖家ID
  20. private int userId;
  21. //卖家姓名
  22. private int userName;
  23. //买家年龄
  24. private int age;
  25. //卖家性别
  26. private String sex;
  27. //卖家所在地区
  28. private String area;
  29. //卖家电话
  30. private int number;
  31. /**
  32. * @return the userId
  33. */
  34. public int getUserId() {
  35. return userId;
  36. }
  37. /**
  38. * @param userId the userId to set
  39. */
  40. public void setUserId(int userId) {
  41. this.userId = userId;
  42. }
  43. /**
  44. * @return the userName
  45. */
  46. public int getUserName() {
  47. return userName;
  48. }
  49. /**
  50. * @param userName the userName to set
  51. */
  52. public void setUserName(int userName) {
  53. this.userName = userName;
  54. }
  55. /**
  56. * @return the age
  57. */
  58. public int getAge() {
  59. return age;
  60. }
  61. /**
  62. * @param age the age to set
  63. */
  64. public void setAge(int age) {
  65. this.age = age;
  66. }
  67. /**
  68. * @return the sex
  69. */
  70. public String getSex() {
  71. return sex;
  72. }
  73. /**
  74. * @param sex the sex to set
  75. */
  76. public void setSex(String sex) {
  77. this.sex = sex;
  78. }
  79. /**
  80. * @return the area
  81. */
  82. public String getArea() {
  83. return area;
  84. }
  85. /**
  86. * @param area the area to set
  87. */
  88. public void setArea(String area) {
  89. this.area = area;
  90. }
  91. /**
  92. * @return the number
  93. */
  94. public int getNumber() {
  95. return number;
  96. }
  97. /**
  98. * @param number the number to set
  99. */
  100. public void setNumber(int number) {
  101. this.number = number;
  102. }
  103. }
  1. /**
  2. * TradingInf.java
  3. * Version 1.0.0
  4. * Created on 2017年5月12日
  5. * Copyright Wangqingang
  6. *
  7. */
  8. package beans;
  9. /**
  10. * @author Wangqinggang
  11. * @version 1.0.0
  12. * @since
  13. * 创建时间:2017年5月12日
  14. * 功能描述:
  15. * 官方网站:www.study821.com
  16. * 邮箱地址:599255294@qq.com
  17. */
  18. public class TradingInf {
  19. //交易ID
  20. private String tradingId;
  21. //交易商品ID
  22. private int tradingGoodsId;
  23. //交易卖家ID
  24. private int tradingUserID;
  25. //交易数量
  26. private int tradingNumber;
  27. /**
  28. * @return the tradingId
  29. */
  30. public String getTradingId() {
  31. return tradingId;
  32. }
  33. /**
  34. * @param tradingId the tradingId to set
  35. */
  36. public void setTradingId(String tradingId) {
  37. this.tradingId = tradingId;
  38. }
  39. /**
  40. * @return the tradingGoodsId
  41. */
  42. public int getTradingGoodsId() {
  43. return tradingGoodsId;
  44. }
  45. /**
  46. * @param tradingGoodsId the tradingGoodsId to set
  47. */
  48. public void setTradingGoodsId(int tradingGoodsId) {
  49. this.tradingGoodsId = tradingGoodsId;
  50. }
  51. /**
  52. * @return the tradingUserID
  53. */
  54. public int getTradingUserID() {
  55. return tradingUserID;
  56. }
  57. /**
  58. * @param tradingUserID the tradingUserID to set
  59. */
  60. public void setTradingUserID(int tradingUserID) {
  61. this.tradingUserID = tradingUserID;
  62. }
  63. /**
  64. * @return the tradingNumber
  65. */
  66. public int getTradingNumber() {
  67. return tradingNumber;
  68. }
  69. /**
  70. * @param tradingNumber the tradingNumber to set
  71. */
  72. public void setTradingNumber(int tradingNumber) {
  73. this.tradingNumber = tradingNumber;
  74. }
  75. }
  1. /**
  2. * Profit.java
  3. * Version 1.0.0
  4. * Created on 2017年5月12日
  5. * Copyright Wangqingang
  6. *
  7. */
  8. package beans;
  9. /**
  10. * @author Wangqinggang
  11. * @version 1.0.0
  12. * @since
  13. * 创建时间:2017年5月12日
  14. * 功能描述:
  15. * 官方网站:www.study821.com
  16. * 邮箱地址:599255294@qq.com
  17. */
  18. public class Profit {
  19. //商品名称
  20. private String goodsName;
  21. //商品Id
  22. private int goodsId;
  23. //成本价
  24. private int costPrice;
  25. //售价
  26. private int sellingPrice;
  27. //交易数量
  28. private int tradingNum;
  29. //交易数量
  30. private int times;
  31. /**
  32. * @return the goodsName
  33. */
  34. public String getGoodsName() {
  35. return goodsName;
  36. }
  37. /**
  38. * @param goodsName the goodsName to set
  39. */
  40. public void setGoodsName(String goodsName) {
  41. this.goodsName = goodsName;
  42. }
  43. /**
  44. * @return the goodsId
  45. */
  46. public int getGoodsId() {
  47. return goodsId;
  48. }
  49. /**
  50. * @param goodsId the goodsId to set
  51. */
  52. public void setGoodsId(int goodsId) {
  53. this.goodsId = goodsId;
  54. }
  55. /**
  56. * @return the costPrice
  57. */
  58. public int getCostPrice() {
  59. return costPrice;
  60. }
  61. /**
  62. * @param costPrice the costPrice to set
  63. */
  64. public void setCostPrice(int costPrice) {
  65. this.costPrice = costPrice;
  66. }
  67. /**
  68. * @return the sellingPrice
  69. */
  70. public int getSellingPrice() {
  71. return sellingPrice;
  72. }
  73. /**
  74. * @param sellingPrice the sellingPrice to set
  75. */
  76. public void setSellingPrice(int sellingPrice) {
  77. this.sellingPrice = sellingPrice;
  78. }
  79. /**
  80. * @return the tradingNum
  81. */
  82. public int getTradingNum() {
  83. return tradingNum;
  84. }
  85. /**
  86. * @param tradingNum the tradingNum to set
  87. */
  88. public void setTradingNum(int tradingNum) {
  89. this.tradingNum = tradingNum;
  90. }
  91. /**
  92. * @return the times
  93. */
  94. public int getTimes() {
  95. return times;
  96. }
  97. /**
  98. * @param times the times to set
  99. */
  100. public void setTimes(int times) {
  101. this.times = times;
  102. }
  103. /**
  104. * @return the profit
  105. */
  106. public int getProfit() {
  107. return profit;
  108. }
  109. /**
  110. * @param profit the profit to set
  111. */
  112. public void setProfit(int profit) {
  113. this.profit = profit;
  114. }
  115. private int profit;
  116. }

3.3 数据库处理类

  1. /**
  2. * JdbcConn.java
  3. * Version 1.0.0
  4. * Created on 2017年5月12日
  5. * Copyright Wangqingang
  6. *
  7. */
  8. package jdbc;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.sql.Statement;
  15. import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
  16. /**
  17. * @author Wangqinggang
  18. * @version 1.0.0
  19. * @since
  20. * 创建时间:2017年5月12日
  21. * 功能描述:
  22. * 官方网站:www.study821.com
  23. * 邮箱地址:599255294@qq.com
  24. */
  25. public class JdbcConn {
  26. private static String url="jdbc:oracle:thin:@localhost:1521:orcl";
  27. private static String user="muke";
  28. private static String password ="muke";
  29. public static Connection conn;
  30. public static PreparedStatement ps;
  31. public static ResultSet rs;
  32. public static Statement st;
  33. public static Connection getConnection(){
  34. try {
  35. Class.forName("oracle.jdbc.driver.OracleDriver");
  36. try {
  37. conn=DriverManager.getConnection(url,user,password);
  38. } catch (SQLException e) {
  39. // TODO Auto-generated catch block
  40. e.printStackTrace();
  41. }
  42. } catch (Exception e) {
  43. // TODO Auto-generated catch block
  44. e.printStackTrace();
  45. }
  46. return conn;
  47. }
  48. }

3.4 service类的实现

3.5 JSP页面的实现

补充:java注释:
在Eclipse中怎样写Java注释
Eclipse Java注释模板设置详解

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注