在此贴一个实例吧。。我会把打印的部分,以不同的颜色着重突出,在此很感谢一个网友提供这样的资料给我。
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="
http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri=" http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri=" http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri=" http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri=" http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri=" http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri=" http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri=" http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri=" http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<html:html lang="true">
<head>
<html:base />
<title>打印订单信息</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path=" //Software//Microsoft//Internet Explorer//PageSetup//";
//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
} catch(e){}
}
//恢复网页打印的页眉页脚
function PageSetup_default(){
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}catch(e){}
}
function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览
PageSetup_Null();
wb.execwb(7,1);
}
function printit(){
if (confirm('确定打印吗?')) {
PageSetup_Null();
wb.execwb(6,6)
}
}
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
var HKEY_Root,HKEY_Path,HKEY_Key;
HKEY_Root="HKEY_CURRENT_USER";
HKEY_Path=" //Software//Microsoft//Internet Explorer//PageSetup//";
//设置网页打印的页眉页脚为空
function PageSetup_Null()
{
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"");
} catch(e){}
}
//恢复网页打印的页眉页脚
function PageSetup_default(){
try {
var Wsh=new ActiveXObject("WScript.Shell");
HKEY_Key="header";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P");
HKEY_Key="footer";
Wsh.RegWrite(HKEY_Root+HKEY_Path+HKEY_Key,"&u&b&d");
}catch(e){}
}
function printsetup(){
// 打印页面设置
wb.execwb(8,1);
}
function printpreview(){
// 打印页面预览
PageSetup_Null();
wb.execwb(7,1);
}
function printit(){
if (confirm('确定打印吗?')) {
PageSetup_Null();
wb.execwb(6,6)
}
}
</script>
<style type="text/css" media=print>
.noprint {
display: none;
}
</style>
<style type="text/css" media=print>
.noprint {
display: none;
}
</style>
</head>
<body>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0
id=wb name=wb width=0></OBJECT>
<table border="0">
<tr>
<td colspan="4">
单位:中国联通利客来网上超市
</td>
</tr>
<tr>
<td colspan="4">
=================================
</td>
</tr>
<tr>
<td>
商品名称
</td>
<td>
数量
</td>
<td>
单价
</td>
<td>
总价
</td>
</tr>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<c:forEach items="${orders.orderdetailses}" var="orderdetail">
<tr>
<td>
${orderdetail.products.productName}
</td>
<td>
${orderdetail.quantity}
</td>
<td>
${orderdetail.unitPrice}
</td>
<td>
${orderdetail.quantity*orderdetail.unitPrice}
</td>
</tr>
</c:forEach>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<tr>
<td colspan="4">
合计:${orders.ATotalPrice}
</td>
</tr>
<tr>
<td colspan="2">
本次积分:${point }
</td>
<td colspan="2">
累计积分:${points }
</td>
</tr>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<c:forEach items="${orders.giftorders}" var="giftorder">
<tr>
<td>礼品:${giftorder.gift.giftName}</td>
</tr>
</c:forEach>
<tr>
<td colspan="4">
谢谢您的惠顾,欢迎您再次光临!
</td>
</tr>
<tr>
<td colspan="4">
请保留好小票,${date}
</td>
</tr>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<tr>
<td colspan="4">
收货人:${orders.shipToName }
</td>
</tr>
<tr>
<td colspan="4">
收货人手机号:${orders.shipMobile }
</td>
</tr>
<tr>
<td colspan="4">
收货人地址:${address }
</td>
</tr>
<tr>
<td colspan="4">
=================================
</td>
</tr>
<tr>
<td colspan="4">
<input type=button name=button_print value="打印" class="noprint"
onClick="javascript:printit()">
<input type=button name=button_setup value="打印页面设置" class="noprint"
onClick="javascript:printsetup();">
<input type=button name=button_show value="打印预览" class="noprint"
onClick="javascript:printpreview();">
<input type="button" name="btn" value="返回" class="noprint"
οnclick="javascript:history.go(-1);" />
</td>
</tr>
</table>
</body>
</html:html>
<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height=0
id=wb name=wb width=0></OBJECT>
<table border="0">
<tr>
<td colspan="4">
单位:中国联通利客来网上超市
</td>
</tr>
<tr>
<td colspan="4">
=================================
</td>
</tr>
<tr>
<td>
商品名称
</td>
<td>
数量
</td>
<td>
单价
</td>
<td>
总价
</td>
</tr>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<c:forEach items="${orders.orderdetailses}" var="orderdetail">
<tr>
<td>
${orderdetail.products.productName}
</td>
<td>
${orderdetail.quantity}
</td>
<td>
${orderdetail.unitPrice}
</td>
<td>
${orderdetail.quantity*orderdetail.unitPrice}
</td>
</tr>
</c:forEach>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<tr>
<td colspan="4">
合计:${orders.ATotalPrice}
</td>
</tr>
<tr>
<td colspan="2">
本次积分:${point }
</td>
<td colspan="2">
累计积分:${points }
</td>
</tr>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<c:forEach items="${orders.giftorders}" var="giftorder">
<tr>
<td>礼品:${giftorder.gift.giftName}</td>
</tr>
</c:forEach>
<tr>
<td colspan="4">
谢谢您的惠顾,欢迎您再次光临!
</td>
</tr>
<tr>
<td colspan="4">
请保留好小票,${date}
</td>
</tr>
<tr>
<td colspan="4">
---------------------------------
</td>
</tr>
<tr>
<td colspan="4">
收货人:${orders.shipToName }
</td>
</tr>
<tr>
<td colspan="4">
收货人手机号:${orders.shipMobile }
</td>
</tr>
<tr>
<td colspan="4">
收货人地址:${address }
</td>
</tr>
<tr>
<td colspan="4">
=================================
</td>
</tr>
<tr>
<td colspan="4">
<input type=button name=button_print value="打印" class="noprint"
onClick="javascript:printit()">
<input type=button name=button_setup value="打印页面设置" class="noprint"
onClick="javascript:printsetup();">
<input type=button name=button_show value="打印预览" class="noprint"
onClick="javascript:printpreview();">
<input type="button" name="btn" value="返回" class="noprint"
οnclick="javascript:history.go(-1);" />
</td>
</tr>
</table>
</body>
</html:html>
说明:要使这个控件起作用,必须使Internate选项里面一些active插件启用。红色的字样在页面中一定要有,其中打印页面设置的边距一般为19.05,最好使它不变,因为这边一变,就意味着客户那边也要做相应的调整,这代价太大了。。