现在每次形成pdf文件时,总是嵌在网页里面的,是在什么地方有个设置么?多谢了

解决方案 »

  1.   

    楼主顺便帮我看看我的报表为什么中的数据都为null
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>TestReport</title>
    <style type="text/css">
    <!--
    .STYLE1 {font-size: 36px}
    .style7 {color: #FF0000}
    -->
    </style>
    </head>
    <body>
    <%@ page import="net.sf.jasperreports.engine.*"%>
    <%@ page import="net.sf.jasperreports.engine.util.*"%>
    <%@ page import="net.sf.jasperreports.engine.export.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.sql.*"%>
    <% 
      final String DATABASE_URL ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DataOperationPlatform";
      final String DATABASE_USER ="sa";
      final String DATABASE_PASSWORD ="";
      Connection conn=null;
      Statement stmt=null;
      ResultSet rs=null;
      String fileName="";

    try
    {
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); }catch(ClassNotFoundException e)
    {
    out.println(e.getMessage());
    }
    try
    {
      conn=DriverManager.getConnection(DATABASE_URL,DATABASE_USER,DATABASE_PASSWORD);  File reportFile = new File(application.getRealPath("FirstReport.jasper"));
    Map parameters = new HashMap(); 
    //parameters.put("filename","111");  byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters,new JREmptyDataSource());
            response.setContentType("application/pdf"); 
      
            response.setContentLength(bytes.length); 
        FileOutputStream fos=new FileOutputStream("c:\\MyReport.pdf");
        fos.write(bytes);
        fos.close();
       }  
    catch (SQLException ex) 
    {
            ex.printStackTrace();
    }
    catch (JRException e)
    {
           e.printStackTrace();
    }
    %>
    </body>
    </html>
      

  2.   

    呵呵,多谢楼上的提醒。我也碰到过一次结果是null的情况,那是因为我在编译*.xml的时候没有使用动态连接,你试试看。有兴趣一起研究一下,我的msn:[email protected]