我正在使用 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 文件并粘贴到 tomcat Apache Software Foundation\Tomcat 6.0\webapps
目录中,然后使用 services.msc 启动了 tomcat。
此时,它没有显示列出的打印机详细信息,也没有打印。
我放了一些记录器,我发现代码卡在 exporter.exportReport();
此行代码未执行后。
请建议我如何使用 jasper 从客户端打印
最佳答案
对我来说似乎是访问权限问题。
打印机是网络打印机吗?然后确保您的 Tomcat-Service 具有访问网络的权限。如果您将 Tomcat 作为 Windows 服务启动,则 Tomcat 默认以“本地系统用户”身份运行,并且无权访问网络。这将解释没有列出打印机并且您无法打印。 Eclipse 由您启动,因此 eclipse-process 拥有您的权限,可以访问网络和打印机。
要更改 Tomcat 服务用户,请转至 Windows 服务 --> 右键单击 Tomcat 服务 --> 属性 --> 登录 --> 此帐户 --> 键入具有权限的用户的名称/密码通过网络访问打印机(也许是你 :))。
希望它能有所帮助,即使这个问题是一个月前的问题。
关于java - 当我使用 services.msc 启动服务器时,在 tomcat 中打印不起作用(从客户端我们无法打印),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17390207/