servlet/jsp中的打印对话框
我想在servlet/jsp中显示打印对话框。下面是我的代码:servlet/jsp中的打印对话框,jsp,servlets,printdialog,Jsp,Servlets,Printdialog,我想在servlet/jsp中显示打印对话框。下面是我的代码: DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet () ; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet () ;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = javax.print.ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null)
{
DocPrintJob job = service.createPrintJob();
Doc doc = new SimpleDoc(decodedImageData, flavor, null);
job.print(doc, null);
}
它在独立应用程序中运行良好。但是,我无法在servlet/jsp中显示打印对话框。您需要知道,在这里执行代码的不是客户机。是服务器
您必须创建一个javascript函数才能工作。我将调用
window.print()代码>在javascript中。在下面试试
<html>
<body>
<a href="javascript:print()">Print</a>
</body>
</html>