由于中文的问题,所以还需要下载:itext-1.02b.jar和iTextAsian.jar包
在properties里需修改font为某种系统内的中文字体,PDF font name选择STSong_Light,选中PDF Embeded PDF Encoding为UniGB-UCS2-H(Chinese simplified)。并且将iTextAsian.jar加入到ireport的lib文件夹下,这样通过ireport产生的pdf文件就支持中文了。
记得把itext-1.02b.jar跟iTextAsian.jar放到JBOSS的LIB下,不然找不到。
<%@ page contentType="text/html;charset=GB2312" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>abc</title>
</head>
<body>
<%
System.out.println("chenggong");
File reportFile = new File(application.getRealPath("aall.jasper"));
System.out.println("chenggong");
Map parameters = new HashMap();
parameters.put("name", "p");
Connection conn=null;
try
{
Class.forName("org.gjt.mm.mysql.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost/music?useUnicode=true&characterEncoding=GB2312","root","c5757078");
System.out.println("chenggong");
}
catch(Exception e)
{
System.out.println(e);
}
JasperRunManager run=new JasperRunManager();
System.out.println("abc");
byte[] bytes = run.runReportToPdf(reportFile.getPath(), parameters, conn);
System.out.println("abc");
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
%>
</body>
</html>