1,首先,在jsp页面中加入打印组件:
<object id="WebPrint" classid="clsid:B3C860B8-1EDD-4BBF-B8A4-74238982457A" height=10 width=100 align="center" hspace=0 vspace=0></object>
加入打印事件表单:
<form id="frmPrint" name="frmPrint" method="post" action="">
<input name="DepositPreview" type="submit" id="DepositPreview" value="print" onClick="PreviewDeposit();"/>
</form>
2,引入打印后台逻辑类,
<%@ page import="WebPrint.PrintFunction"%>,
3,调用javaBean:<jsp:useBean id="pf" scope="page" class="WebPrint.PrintFunction"/>
4,加入js打印函数:调用后会重新刷新页面;
function PreviewDeposit(){
document.frmPrint.action="materialDetailList.jsp?PrintType=DepositPreview";
document.frmPrint.submit();
}
5,加入jsp打印控制逻辑,用out动态输出真正实现打印的js:
<%
String PrintType=request.getParameter("PrintType");
String ReportPath="d:\\jy\\jboss-3.5-DDDO\\server\\default\\deploy\\stringbeans.war\\Mis\\materialMng\\materialPlan\\";
System.out.println(PrintType);
if(PrintType==null){
}else if(PrintType.equals("DepositPreview")){
//pf.OpenDataConnection();
String PrintValue="111111111";//pf.TableToXml("select top 1 * from gdms.t_reqmaterial");
String FileValue=pf.FileToStr(ReportPath+"MaterialDetail.fr3");
System.out.println("FileValue:"+FileValue);
String ParaName="ShopName`~PrintDepositAdd`~PrintPaperNo`~Title";
String ParaValue="测试酒店"
+ "`~说明:本单据为贵客押金收取凭证,盖章有效。退房时请出示,遗失者自负,请妥善保存。退房时间为12:00时,延时退房18:00时以前按半天房费收取,18:00时以后算全天房价。押金单有效期为一个月,过期作废。 贵重物品请交前台寄存,未寄存丢失自负。 谢谢!"
+ "`~身份证:4325011980639512"
+ "`~押金单";
//String ScriptStr="<script language='javascript'>window.οnlοad=function(){try{var ObjPrintMange=new ActiveXObject('WebPrint.WebPrintUnit');}catch(e){if(confirm('打印控件未安装,现在下载吗?')){window.location='./PrintActivex.exe';}return;} var OldVersion=ObjPrintMange.Version;NewVersion='5.0(2011-08-01)';if(OldVersion<NewVersion){ObjPrintMange=null;alert('打印控件需升级。请先进行下载,下载后关闭IE,然后安装升级版。');window.location='./PrintActivex.exe';return;}"
String ScriptStr="<script language='javascript'>window.οnlοad=function(){try{var ObjPrintMange=new ActiveXObject('WebPrint.WebPrintUnit');}catch(e){if(confirm('打印控件未安装,现在下载吗?')){window.location='/stringbeans/Mis/materialMng/materialAffix/materialAffixDown.jsp?filePath=c:&f_name=PrintActivex.exe&f_path=PrintActivex.exe';}return;} var OldVersion=ObjPrintMange.Version;NewVersion='5.0(2011-08-01)';if(OldVersion<NewVersion){ObjPrintMange=null;alert('打印控件需升级。请先进行下载,下载后关闭IE,然后安装升级版。');window.location='./PrintActivex.exe';return;}"
+" ObjPrintMange.CheckReg('公司名称','3B8E5B998A3125EE89983EA940BB2AEE'); "
//+" ObjPrintMange.ReportFileName='MaterialDetail.fr3';"
+" ObjPrintMange.ShowReport('"
//+" ObjPrintMange.DesignReport('"//设计
//+" ObjPrintMange.PrintReport('"
+FileValue+"','"
+ParaName+"','"
+ParaValue+"','"
+PrintValue+"','','','','','');"
+" ObjPrintMange=null;}</script>";
out.println(ScriptStr);
}
%>