Struts218+JasperReport371结合iReport371报表开发.docx

上传人:b****5 文档编号:3025759 上传时间:2022-11-17 格式:DOCX 页数:19 大小:581.06KB
下载 相关 举报
Struts218+JasperReport371结合iReport371报表开发.docx_第1页
第1页 / 共19页
Struts218+JasperReport371结合iReport371报表开发.docx_第2页
第2页 / 共19页
Struts218+JasperReport371结合iReport371报表开发.docx_第3页
第3页 / 共19页
Struts218+JasperReport371结合iReport371报表开发.docx_第4页
第4页 / 共19页
Struts218+JasperReport371结合iReport371报表开发.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

Struts218+JasperReport371结合iReport371报表开发.docx

《Struts218+JasperReport371结合iReport371报表开发.docx》由会员分享,可在线阅读,更多相关《Struts218+JasperReport371结合iReport371报表开发.docx(19页珍藏版)》请在冰豆网上搜索。

Struts218+JasperReport371结合iReport371报表开发.docx

Struts218+JasperReport371结合iReport371报表开发

用Struts2生成OpenFlashChart2图表数据

准备以下开源项目:

1.Struts2.1.6

2.OpenFlashChart2Version2LugWyrmCharmer(28th,July2009)

3.jofc2,这东西不知道是没做好还是什么意思,好像和ofc2不怎么匹配,最好下源码,有什么问题直接改。

4.log4j

用eclipse新建动态网站,取名OFC2Demo,将Struts2lib目录下commons-fileupload-1.2.1.jar、commons-logging-1.0.4.jar、freemarker-2.3.13.jar、ognl-2.6.11.jar、struts2-core-2.1.6.jar、xstream-1.3.1.jar和xwork-2.1.2.jar、log4j.jar复制到WebContent\lib目录下。

使用svn下载jofc2源码,

在web.xml中加入struts2拦截器

xml version="1.0" encoding="UTF-8"?

>

xsi="http:

//www.w3.org/2001/XMLSchema-instance" xmlns=" xmlns:

web=" xsi:

schemaLocation="  id="WebApp_ID" version="2.5">

  OFC2Demo

  

    struts2

    org.apache.struts2.dispatcher.FilterDispatcher

  

  

    struts2

    /*

  

  

    index.html

    index.htm

    index.jsp

    default.html

    default.htm

    default.jsp

  

在返回jofc2生成OpenFlashChart数据时,本来想用jsonplugin插件,但发现序列化jofc2的Chart对象时,许多元素名称和Chart.toString()不同,这使得OpenFlashChart解析数据时不认识。

所以需增加一个Struts2自定义ResultType,步骤如下:

新建类,OFC2Plugin

package com.xy.strutsplugin;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import jofc2.model.Chart;

import mons.logging.Log;

import mons.logging.LogFactory;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionContext;

import com.opensymphony.xwork2.ActionInvocation;

import com.opensymphony.xwork2.Result;

import com.opensymphony.xwork2.util.ValueStack;

public class OFC2Resultimplements Result {

    private static final Log log = LogFactory.getLog(OFC2Result.class);

    public void execute(ActionInvocation invocation) throws Exception {

        ActionContext actionContext = invocation.getInvocationContext();

        HttpServletResponse response = (HttpServletResponse) actionContext.get(StrutsStatics.HTTP_RESPONSE);

        

        try {

            ValueStack stack = invocation.getStack();

            Chart chart = (Chart)stack.findValue("ofcChart");

            

            response.setContentType("application/json-rpc;charset=utf-8");

            response.setHeader("Cache-Control", "no-cache");

            response.setHeader("Expires", "0");

            response.setHeader("Pragma", "No-cache");

            

            PrintWriter out = response.getWriter();

            log.debug(chart.toString());

            out.print(chart.toString());

        } catch (IOException exception) {

            log.error(exception.getMessage(), exception);

            throw exception;

        }

    }

}

在src下新建struts-plugin.xml

xml version="1.0" encoding="UTF-8" ?

>

DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

        "http:

//struts.apache.org/dtds/struts-2.0.dtd">

    

        

            

        

    

配置log4j,以查看json输出信息。

在src下增加两个文件

commons-logging.properties

## set Log as Log4j

mons.logging.Log=mons.logging.impl.Log4JLogger

log4j.properties

# This is the configuring for logging displayed in the Application Server

log4j.rootCategory=DEBUG,stdout

#stdout configure

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern= %d %p [%c] - <%m>%n

##

.xy.strutsplugin.OFC2Result=DEBUG

好了,现在将ofc所需的包添加到项目中

在WebContent目录下添加文件夹ofc2,将open-flash-chart-2-Lug-Wyrm-Charmer目录下的open-flash-chart.swf和js目录复制到新建的ofc2目录下。

演示LineChart

在Action层增加类LineAction

package com.xy.action;

import java.text.DateFormat;

import java.util.ArrayList;

import java.util.Date;

import java.util.List;

import java.util.Locale;

import jofc2.model.Chart;

import jofc2.model.elements.LineChart;

import jofc2.model.axis.YAxis;

import jofc2.model.Text;

import com.opensymphony.xwork2.ActionSupport;

public class LineAction extends ActionSupport{

    

    private Chart ofcChart;

    public Chart getOfcChart() {

        return ofcChart;

    }

    

    public String dot(){

    

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1