Finereport与Java Web

参考帮助文档


1.web.xml 配置

<servlet>
    <servlet-name>ReportServerservlet-name>
    <servlet-class>com.fr.web.ReportServletservlet-class>
    <load-on-startup>0load-on-startup>
  servlet>

  <servlet-mapping>
    <servlet-name>ReportServerservlet-name>
    <url-pattern>/ReportServerurl-pattern>
  servlet-mapping>

2.相关配置的导入

将%FineReport_HOME%\WebReport\WEB-INF目录下面的classes,lib,reportlets,resources四个目录复制到%Tomcat_HOME% \webapps\examples\WEB-INF下。


3. .jsp页面的配置

实例一:


<html>
 <head>
  <title>FineReport Demotitle>
  <meta http-equiv="Content-Type" content="text/html; charset=GBK" />
 head>
 <body>
 <iframe id="reportFrame" width="900" height="400" src="../项目名/ReportServer?reportlet=模板.cpt">iframe>
 body>
html>

实例二:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<html>
  <head>  
  <title>FineReport Demotitle>  
  <meta http-equiv="Content-Type" content="text/html; charset=GBK" />  
  <script type="text/javascript">
    //cjkEncode方法的实现代码,放在网页head中或者用户自己的js文件中
    function cjkEncode(text) {                                                                          
      if (text == null) {       
        return "";       
      }       
      var newText = "";       
      for (var i = 0; i < text.length; i++) {       
        var code = text.charCodeAt (i);        
        if (code >= 128 || code == 91 || code == 93) {  //91 is "[", 93 is "]".       
          newText += "[" + code.toString(16) + "]";       
        } else {       
          newText += text.charAt(i);       
        }       
      }       
      return newText;       
    }   

    function autoSubmit() {
      var num = document.getElementById('num').value; //获取文本控件的值
      var row = document.getElementById('row').value; //获取下拉框控件的值
      //拼接出最终报表访问路径,并对完整的路径进行编码转换,防止乱码问题
      var reportURL = cjkEncode("../Text_Finereport/ReportServer?reportlet=WorkBook7.cpt");
        document.paraForm.action = reportURL; //通过form的name获取表单,并将报表访问路径赋给表单的action
      document.paraForm.submit(); //触发表单提交事件
    }
  script>
  head>  
  <body>
    <fieldset>
    <legend>查询表单:legend>
    <form name="paraForm" method="post" target="reportFrame">
        最小库存量:<input type="text" name="num" id="num" value="1"/>
        每页显示行数:<select name="row" id="row">  
        <option value="10" select>10  
        <option value="20">20
        <option value="30">30
        <input type="button" name="show" value="查询" onclick="autoSubmit()"/>
    form> 
    fieldset>
    <iframe id="reportFrame" name="reportFrame" width="50%" height="50%" >iframe>  
  body>  
html>

模板位于 web项目下 WEB-INF/reportlets

你可能感兴趣的:(JavaWeb开发学习笔记)