3

我正在使用JasperReports 1.3.1打印报告。我正在为开发目的唱歌 eclipse 和 tomcat。

在 Eclipse 中,当我运行应用程序时,下面的代码将显示列出的打印机设备和打印按钮。如果我单击打印按钮,则报告将由所选设备打印。

PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A5);
PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();

在这里,我将 jasperPrint 作为我手动构造的参数传递。它工作得很好

我的问题是:

我创建了 war 文件并粘贴在 tomcatApache Software Foundation\Tomcat 6.0\webapps目录中,并使用services.msc启动了 tomcat 。

此时,它不显示列出的打印机详细信息,也不打印。

我放了一些记录器,我发现,exporter.exportReport(); 在这行代码没有执行之后,代码就挂了。请建议我如何使用 jasper 从客户端打印

4

1 回答 1

2

对我来说,这似乎是一个访问权限问题。

打印机是网络打印机吗?然后确保您的 Tomcat-Service 具有网络访问权限。如果您将 Tomcat 作为 Windows 服务启动,则 Tomcat 默认以“本地系统用户”身份运行,并且无权访问网络。这将解释没有列出打印机并且您无法打印。Eclipse是你自己启动的,所以eclipse-process拥有你的权限,可以访问网络和打印机。

要更改 Tomcat-Service 用户,请转到 Windows 服务 --> 右键单击​​ Tomcat 服务 --> 属性 --> 登录 --> 此帐户 --> 键入有权访问的用户的名称/密码网络上的打印机(也许你:))。

希望它有所帮助,即使问题是一个月前的问题。

于 2013-10-08T08:29:04.487 回答