Java 通过tomcat在默认打印机上打印
我正在开发一个带有web服务TomCat和laboratory(Eclipse Java EE)的集成Android应用程序。她达到了令人满意的水平,在默认打印机上执行查询和显示,一切都很安静,但当我得到TomCat的服务时,他没有执行打印,就好像没有打印机连接到服务器一样 当我直接从Eclipse提供服务时,下面的代码用于执行打印Java 通过tomcat在默认打印机上打印,java,tomcat,printing,Java,Tomcat,Printing,我正在开发一个带有web服务TomCat和laboratory(Eclipse Java EE)的集成Android应用程序。她达到了令人满意的水平,在默认打印机上执行查询和显示,一切都很安静,但当我得到TomCat的服务时,他没有执行打印,就好像没有打印机连接到服务器一样 当我直接从Eclipse提供服务时,下面的代码用于执行打印 try{ InputStream prin = new ByteArrayInputStream(textoimp.getBytes()); INPUT_STRE
try{
InputStream prin = new ByteArrayInputStream(textoimp.getBytes());
INPUT_STREAM docFlavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
SimpleDoc documentoTexto = new SimpleDoc(prin, docFlavor, null);
PrintService impressora = PrintServiceLookup.lookupDefaultPrintService(); // pega a impressora padrao
PrintRequestAttributeSet printerAttributes = new HashPrintRequestAttributeSet();
printerAttributes.add(new JobName("Impressao", null));
printerAttributes.add(OrientationRequested.PORTRAIT);
printerAttributes.add(MediaSizeName.ISO_A4); // informa o tipo de folha
DocPrintJob printJob = ((PrintService) impressora).createPrintJob(); //the error occurs here , the printer is null
try{
printJob.print(documentoTexto, (PrintRequestAttributeSet)printerAttributes);//try to print
}
catch(PrintException e){
e.printStackTrace();
JOptionPane.showMessageDialog(null, "Não foi possível realizar a impressão !!", "Erro", JOptionPane.ERROR_MESSAGE);
}
prin.close();
}
catch(Exception e){
e.printStackTrace();
return false;
}
但是,当服务在Tomcat中运行时,它不起作用,有人能帮我吗?由Arjan says Tijms回答,有一个问题回答了,我没有看到,我感谢这位朋友。 以下是答案的链接:
“它不起作用”-请提供详细信息。到底是什么不起作用,任何异常堆栈跟踪?顺便说一句:在后台Web服务中使用Swing对话框(JOptionPane)似乎是错误的…使默认打印机始终错误的要求,因为在Tomcat中使用WS-this时返回null。关于JOptionPane,你是对的,对不起,这是因为我现在开始。你检查了一些关于JOptionPane的问题了吗?