java action classpublic void printNew(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;
System.out.println("printNew 2");
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
if (defaultService != null)
{
try
{
DocPrintJob job = defaultService.createPrintJob();
FileInputStream fis = new FileInputStream("hello.html");
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}我使用的html文件<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UNLOADING DOCUMENT</title>
</head>
<body>
<h1 align="center"><b><font color="#000080"><u>UNLOADING DOCUMENT</u></font></b></h1>
</body>
</html>
但是每次打印总是报错
[3/23/10 11:08:44:265 EDT] 00000082 SystemErr R sun.print.PrintJobFlavorException: invalid flavor
[3/23/10 11:08:44:296 EDT] 00000082 SystemErr R at sun.print.Win32PrintJob.print(Win32PrintJob.java:346)
[3/23/10 11:08:44:296 EDT] 00000082 SystemErr R at com.knightedcs.wms.configuration.struts.actions.UpdateLngSettingAction.printNew(UpdateLngSettingAction.java:454)请大家帮忙看看什么原因吧,谢谢啦
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;
System.out.println("printNew 2");
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
if (defaultService != null)
{
try
{
DocPrintJob job = defaultService.createPrintJob();
FileInputStream fis = new FileInputStream("hello.html");
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}我使用的html文件<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UNLOADING DOCUMENT</title>
</head>
<body>
<h1 align="center"><b><font color="#000080"><u>UNLOADING DOCUMENT</u></font></b></h1>
</body>
</html>
但是每次打印总是报错
[3/23/10 11:08:44:265 EDT] 00000082 SystemErr R sun.print.PrintJobFlavorException: invalid flavor
[3/23/10 11:08:44:296 EDT] 00000082 SystemErr R at sun.print.Win32PrintJob.print(Win32PrintJob.java:346)
[3/23/10 11:08:44:296 EDT] 00000082 SystemErr R at com.knightedcs.wms.configuration.struts.actions.UpdateLngSettingAction.printNew(UpdateLngSettingAction.java:454)请大家帮忙看看什么原因吧,谢谢啦
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货