报表知识库
我要提问

servlet实现保存当前预览数据为rat文件

需求说明

润乾报表展现数据,通常是实时从数据源中取出数据展现的。但如果用户因为业务需求,例如因数据库中数据常常变化,想保存某次预览的数据,如果需要预览新数据则重新加载,类似这样的需求如何来满足呢?

 

解决方案

润乾有一种文件方式为rat文件即可以将数据内建保存起来,通过调用转换rat文件将当前预览的报表数据保存起来,首次预览显示rat文件的数据,需要重新加载新数据则调用raq文件。

 

具体实现代码:

 

    public void doGet(HttpServletRequest request, HttpServletResponse response)

            throws ServletException, IOException {

            //获取项目下报表路径,并获得报表名称

            String raqName = request.getParameter(“raq”);

         String path = this.getServletConfig().getServletContext().getRealPath(“/”);

         path= path+”reportFiles\\”+raqName;

     String newPath = path.substring(0, path.length()-1)+”t”;

         System.out.print(path);

            try {

                ReportDefine rd = (ReportDefine) ReportUtils.read(path);

                 Context cxt = new Context();

                   Engine engine = new Engine(rd,cxt);

                    IReport ireport = engine.calc();

                    OutputStream os = new FileOutputStream(newPath);

                    ReportUtils.write(os,ireport);

                    os.close();

 

 

               //  request.setAttribute(“D://test.rat”,ireport);

            } catch (Exception e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }

 

    }

 

发布的jsp中做判断如果报表路径中没有报表名称对应的.rat文件则展现.raq文件,需要保存调用该servlet方法保存为rat文件,如果有,则直接预览.rat文件,需要重新计算则跳转到展现raq文件页面。

 

加载rat文件:

 

<a href=”http://127.0.0.1:6001/demo/reportJsp/testOutPutRaq.jsp”>重新加载</a>

 

<table align=left>

    <tr><td>

        <report:html name=”report1″

            srcType=”file”

            reportFileName=”test.rat”

            funcBarLocation=”top”

            exceptionPage=”/reportJsp/myError2.jsp”

        />

    </td></tr>

</table>

 

加载raq文件:

 

    <a href=”http://localhost:6001/demo/servlet/OutputRat?raq=test.raq” onclick=”action();return false;”>保存</a>

 

<table align=left>

    <tr><td>

        <report:html name=”report1″

            srcType=”file”

            reportFileName=”test.raq”

            funcBarLocation=”top”

            exceptionPage=”/reportJsp/myError2.jsp”

        />

    </td></tr>

</table>

标签: