首页 文章

当我使用services.msc启动服务器时,打印在tomcat中不起作用(从客户端我们无法打印)

提问于
浏览
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文件并粘贴在tomcat Apache Software Foundation\Tomcat 6.0\webapps 目录中,并使用services.msc启动了tomcat .

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

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

1 回答

  • 2

    看起来对我来说是一个访问权问题 .

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

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

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

相关问题