点击“New”创建一种新格式,命名为“宋体”,再进行相关设置,如图:
这样,这个“宋体”的Style就设置好了,在设定字体的时候就不需要再到选项卡一项一项地进行设置,在字体的属性中选择“Common”选项卡,在Style中选择这个“宋体”即可:
4.7 创建显示HTML格式报表的JSP文件 在WebRoot根目录下创建jsp文件testhtml.jsp,内容如下: <%@ page contentType=\ml;charset=GB2312\%> <%@ page import=\%> <%@ page import=\%> <%@ page import=\%> <%@ page import=\%> <% //报表编译之后生成的.jasper文件的存放位置 File reportFile = new File(this.getServletContext(). (1) getRealPath(\)); String url=\ysql://localhost:3306/db\; Class.forName(\.mysql.jdbc.Driver\); Map parameters = new HashMap(); //\R\是报表中定义的参数名称,其类型为String 型 //设置SQLSTR参数的内容,根据需要赋值sql语句 parameters.put(\, \ employee\); (2) Connection conn = DriverManager.getConnection(url, (3) \, \); JasperRunManager.runReportToHtmlFile(reportFile.getPath(), (4) parameters,conn); response.sendRedirect(\ml\); (5)
%> 代码说明: 1. 定位jasper文件 2. 给报表模板中使用到的参数SQLSTR赋值,这里指定一个sql语句 3. 采用JDBC方式连结数据库 4. 生成HTML文件,参数分别为报表文件模板物理位置,报表参数,数据库连结 5. 转向到此页面,这个页面是固定的,需要和报表模板的位置和路径相同 发布项目后预览,输入http://localhost:8080/iReportTest/testhtml.jsp(本例采用tomcat作为web服务器,发布过程参考其他文档,数据库采用的mysql) 效果:
4.8 创建显示PDF格式报表的JSP文件 在WebRoot根目录下创建jsp文件testpdf.jsp,内容如下: <%@ page contentType=\=UTF-8\%> <%@ page import=\%> <%@ page import=\%> <%@ page import=\%> <%@ page import=\%> <% //报表编译之后生成的.jasper文件的存放位置 File reportFile = new File(this.getServletContext(). getRealPath(\)); String url=\ysql://localhost:3306/db\;
Class.forName(\.mysql.jdbc.Driver\); Map parameters = new HashMap(); //\R\是报表中定义的一个参数名称,其类型为String 型 parameters.put(\, \ employee where employee_id like 'Z%'\); Connection conn = DriverManager.getConnection(url, \, \); byte[] bytes=JasperRunManager. runReportToPdf(reportFile.getPath(),parameters,conn); response.setContentType(\); response.setContentLength(bytes.length); ServletOutputStream outStream = response.getOutputStream(); outStream.write(bytes,0,bytes.length); outStream.flush(); outStream.close(); out.clear(); out = pageContext.pushBody(); %> 效果如下: