在csdn上找了很久!我用ireport编译后浏览数据库sqlserver中的数据,显示乱码。
为什么啊?郁闷中!
生成pdf时,没有列表名,只有数据信息且是乱吗改用jsp调用,没成功!提示错误如下!望大家帮忙解决Class not found when loading object from file : C:\Tomcat 5.5\webapps\smsfxh\ireport\personStat.jasper

解决方案 »

  1.   

    你要把 ireport 的 jar 包 (jasperreports-1.2.6.jar)
    放到 你的 web 工程 lib 目录中去。
      

  2.   

    testIreport.jsp<%@ page contentType="text/html;charset=GBK"%>
    <%@ page import="java.util.*"%>
    <%@ page import="net.sf.jasperreports.engine.util.*"%>
    <%@ page import="net.sf.jasperreports.engine.*"%>
    <%@ page import="net.sf.jasperreports.engine.export.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.sql.*"%>
    <%//数据库连接 Connection conn = null;
    try {
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
    .newInstance();
    conn = DriverManager
    .getConnection(
    "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=seliat",
    "sa", "sa");
    } catch (Exception e) {
    out.println("zzz" + e.getMessage());
    }
    //取到编译后的jasper文件
    File reportFile = null; reportFile = new File(application
    .getRealPath("ireport/personStat.jasper"));
    //向报表中定义的参数赋值
    if (reportFile == null)
    return;

    byte[] bytes = null;
    try {
    bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),
    null, conn);
    } catch (Exception eee) {
    out.println(eee.getMessage());
    }
    response.setContentType("application/pdf");
    if (bytes == null) {
    return;
    } response.setContentLength(bytes.length);
    ServletOutputStream ouputStream = response.getOutputStream();
    ouputStream.write(bytes, 0, bytes.length);
    ouputStream.flush();
    ouputStream.close(); %>
      

  3.   

    大家有成功的小例子也可以介绍给我啊![email protected]
    谢谢
    ireport+sqlserver+jsp
    谢谢!
      

  4.   

    我指的是 jasperreport 报表文件,不是jsp,
    分析一下这个问题,你编译jasper的时候,有没有设置 ireport 的 classpath,如果你的报表用到了你自己的类的话,应该是设置了的对吧?否则jasper也编译不出来。那么,在你的web 应用 中也必须把这个classpath 加进去,出现这个错误就是因为你的jasper文件 中用到的类在你的web应用环境中没有找到。
    你可以尝试在命令行方式下编译你的报表,看看结果如何.
      

  5.   

    <?xml version="1.0" encoding="UTF-8"  ?>
    <!-- Created with iReport - A designer for JasperReports -->
    <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
    <jasperReport
     name="personStat"
     columnCount="1"
     printOrder="Vertical"
     orientation="Portrait"
     pageWidth="595"
     pageHeight="842"
     columnWidth="535"
     columnSpacing="0"
     leftMargin="30"
     rightMargin="30"
     topMargin="20"
     bottomMargin="20"
     whenNoDataType="NoPages"
     isTitleNewPage="false"
     isSummaryNewPage="false">
    <property name="ireport.scriptlethandling" value="0" />
    <property name="ireport.encoding" value="UTF-8" />
    <import value="java.util.*" />
    <import value="net.sf.jasperreports.engine.*" />
    <import value="net.sf.jasperreports.engine.data.*" /> <queryString><![CDATA[select *  from personinfo;]]></queryString> <field name="id" class="java.lang.Integer"/>
    <field name="name" class="java.lang.String"/>
    <field name="sex" class="java.lang.String"/>
    <field name="jobtime" class="java.sql.Timestamp"/>
    <field name="salay" class="java.lang.Integer"/> <sortField name="name" />
    <sortField name="sex" />
    <sortField name="jobtime" />
    <sortField name="salay" /> <background>
    <band height="0"  isSplitAllowed="true" >
    </band>
    </background>
    <title>
    <band height="50"  isSplitAllowed="false" >
    <staticText>
    <reportElement
    x="165"
    y="9"
    width="211"
    height="33"
    key="staticText-1"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[人力资源审核报表]]></text>
    </staticText>
    </band>
    </title>
    <pageHeader>
    <band height="50"  isSplitAllowed="true" >
    </band>
    </pageHeader>
    <columnHeader>
    <band height="53"  isSplitAllowed="true" >
    <staticText>
    <reportElement
    x="29"
    y="23"
    width="32"
    height="16"
    key="staticText-2"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[姓名]]></text>
    </staticText>
    <staticText>
    <reportElement
    x="145"
    y="23"
    width="32"
    height="16"
    key="staticText-3"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[性别]]></text>
    </staticText>
    <staticText>
    <reportElement
    x="264"
    y="24"
    width="81"
    height="16"
    key="staticText-4"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[工作时间]]></text>
    </staticText>
    <staticText>
    <reportElement
    x="397"
    y="25"
    width="32"
    height="16"
    key="staticText-5"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[工资]]></text>
    </staticText>
    </band>
    </columnHeader>
    <detail>
    <band height="100"  isSplitAllowed="true" >
    <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
    <reportElement
    x="8"
    y="41"
    width="100"
    height="18"
    key="textField"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement rotation="None">
    <font fontName="宋体" pdfFontName="STSong-Light" size="12" pdfEncoding ="UniGB-UCS2-H"/>
    </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[$F{name}]]></textFieldExpression>
    </textField>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
    <reportElement
    x="126"
    y="45"
    width="100"
    height="18"
    key="textField"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font fontName="仿宋_GB2312"/>
    </textElement>
    <textFieldExpression   class="java.lang.String"><![CDATA[$F{sex}]]></textFieldExpression>
    </textField>
    <textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
    <reportElement
    x="252"
    y="47"
    width="100"
    height="18"
    key="textField"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <textFieldExpression   class="java.sql.Timestamp"><![CDATA[$F{jobtime}]]></textFieldExpression>
    </textField>
    <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
    <reportElement
    x="410"
    y="50"
    width="100"
    height="18"
    key="textField"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <textFieldExpression   class="java.lang.Integer"><![CDATA[$F{salay}]]></textFieldExpression>
    </textField>
    </band>
    </detail>
    <columnFooter>
    <band height="30"  isSplitAllowed="true" >
    </band>
    </columnFooter>
    <pageFooter>
    <band height="50"  isSplitAllowed="true" >
    </band>
    </pageFooter>
    <lastPageFooter>
    <band height="50"  isSplitAllowed="true" >
    <staticText>
    <reportElement
    x="331"
    y="27"
    width="142"
    height="16"
    key="staticText-7"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[审核人员签名:]]></text>
    </staticText>
    </band>
    </lastPageFooter>
    <summary>
    <band height="34"  isSplitAllowed="true" >
    <staticText>
    <reportElement
    x="386"
    y="18"
    width="32"
    height="16"
    key="staticText-6"/>
    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
    <textElement>
    <font/>
    </textElement>
    <text><![CDATA[合计]]></text>
    </staticText>
    </band>
    </summary>
    </jasperReport>
      

  6.   

    我用的是iReport-1.2.8,好象官方网站说,不需要配置吧!呵呵,我也不确定
      

  7.   

    你的文件 我用 ireport打不开,没辙
    jasperreport下载里面有个demo ,里面很多例子包括 webapp 的例子,你去看看吧
      

  8.   

    如果可以,我把personStat.jrxml这个文件传给你,因为沾不上来!!
    哎,弄了好久了!!!!
      

  9.   

    你把那个文件发到我信箱,[email protected]
      

  10.   

    你发的是jasper文件,已经编译过的
      

  11.   

    我把你的jrxml稍微改了一下,用Mysql代替sqlserver
    运行没有问题,除了在jsp四十多行的地方要改一下  try {
    bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),
    parameters, conn);
    } catch (Exception eee) {
    out.println(eee.getMessage());
    }
    你应该就是包的问题,classpath的问题
      

  12.   

    我加载在系统的path的设置中了,不行吗?是不是包的版本的问题啊 ?