jsp 调用jasper 却什么都没显示出来 为什么?
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="
net.sf.jasperreports.engine.*"%>
<%@ page import= "net.sf.jasperreports.view.JasperViewer " %>
<%@ page import="java.io.*"%>
<%
File reportFile = new File(application.getRealPath("ts.jasper"));
System.out.println(reportFile.getPath());
try {
JasperFillManager.fillReportToFile(reportFile.getPath(), null);
//预览报表,false代表不是使用xml文件。
JasperViewer view = new JasperViewer("D:\\DQC_Redo2\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\testt\\ts.jrprint", false);
view.pack();
view.setVisible(true);
}
catch (Exception e) {
e.printStackTrace();
}
%>
jasperviewer 却说没有页面,ts.jasper里面有一行英文的字母.没中文的 高手告诉我为什么 谢谢了!!!
------解决方案--------------------
哦,别人的那个是不是在JSP环境下的啦.
你参考一下下边的代码
<%@ page contentType="application/pdf;charset=GB2312"%>
<%@ page import="dori.jasper.engine.*" %>
<%@ page import="dori.jasper.engine.util.*" %>
<%@ page import="dori.jasper.engine.export.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
//报表编译之后生成的.jasper 文件的存放位置
File reportFile = new File(application.getRealPath("/report/test_report_1.jasper"));
//这个是用来联接我的SQL Server 的JDBC URL
String url ="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=film";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Map parameters = new HashMap();
parameters.put("name", "p");
System.out.println("---------conn-------------");
//连接到数据库
Connection conn =DriverManager.getConnection(url,"sa", "");
System.out.println("---------Jasper begin-------------");
//在控制台显示一下报表文件的物理路径
System.out.println(reportFile.getPath());
byte[] bytes=JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,conn);
System.out.println("---------Jasper end-------------");
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();