詳細參考:http://www.cnblogs.com/aidd2008/archive/2012/04/25/2469994.html
JSP代碼如下:
<%@page import="java.net.URLDecoder"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
String params = request.getParameter("params");
params = URLDecoder.decode(params, "UTF-8");
String[] arr = new String[8];
if (params != null) {
arr = params.split(",");
}
request.setAttribute("arr", arr);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html>
<head>
<base href="<%=basePath%>">
<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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style media=print>
.Noprint {
display: none;
}
.PageNext {
page-break-after: always;
}
</style>
<style type="text/css">
.helpSpan{
margin-left:20px;
cursor:pointer;
display:inline-block;
color:blue;
}
</style>
<script type="text/javascript" src="<%=path%>/js/jquery-1.8.3.min.js"></script>
<title>打印單</title>
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<link rel="stylesheet" type="text/css"
href="css/gzjrzcjys/editFrame.css" />
<script type="text/javascript">
function print1(){
document.all.WebBrowser.ExecWB(6,6);
}
function wOpen(){
$("span.open").hide();
$("span.close").show();
$("#helpContent").show();
}
function wClose(){
$("span.open").show();
$("span.close").hide();
$("#helpContent").hide();
}
var hkey_root, hkey_path, hkey_key;
hkey_root = "HKEY_CURRENT_USER";
hkey_path = "\\software\\Microsoft\\Internet Explorer\\PageSetup\\";
//設置網頁打印的頁眉頁腳邊距為空
function pagesetup_null() {
try {
var RegWsh = new ActiveXObject("WScript.Shell");
hkey_key = "header";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
hkey_key = "footer";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "");
hkey_key = "margin_left";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.0");
hkey_key = "margin_right";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.0");
hkey_key = "margin_top";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.0");
hkey_key = "margin_bottom";
RegWsh.RegWrite(hkey_root + hkey_path + hkey_key, "0.0");
} catch (e) {
alert(e);
}
}
$(document).ready(function(){
pagesetup_null();
});
</script>
</head>
<body>
<div id="frame">
<div id="frame_title">線下資金轉入申請</div>
<div id="frame_content">
<table class="content">
<tr>
<th>收款銀行:</th>
<td><%=arr[0]%></td>
<th>收款方全稱:</th>
<td><%=arr[1]%></td>
</tr>
<tr>
<th>收款方銀行賬號:</th>
<td><%=arr[2]%></td>
<th>充值碼:</th>
<td><%=arr[3]%>(填寫在備注欄)</td>
</tr>
<tr>
<th>匯款銀行:</th>
<td><%=arr[4]%></td>
<th>匯款方全稱:</th>
<td><%=arr[5]%></td>
</tr>
<tr>
<th>匯款賬號:</th>
<td><%=arr[6]%></td>
<th>匯款金額:</th>
<td><%=arr[7]%> 元</td>
</tr>
</table>
</div>
<div id="frame_bottom" class="Noprint">
<a href="javascript:void(0)" class="button_toRound"><span
style="font-size:14px;"
onclick="print1()" class="Noprint">【打印】</span>
</a>
</div>
<div style="padding:12px 5px;background-color:#ffffff" class="Noprint">
備注: 請到網銀或者銀行辦理轉賬業務,轉賬匯款時,信息必須如實填寫,以避免無法如實到賬而給您的投資造成損失!</div>
</div>
<div style="width:750px;margin:auto;margin-top:150px;" class="Noprint">
<div>友情鏈接:</div>
<div>
<table class="content">
<tr>
<td><a href=" </td>
<td><a href=" target="_blank">建設銀行</a>
</td>
<td><a href=" </td>
<td><a href=" </td>
</tr>
<tr>
<td><a href=" target="_blank">光大銀行</a>
</td>
<td><a
href=" target="_blank">交通銀行</a>
</td>
<td><a href=" target="_blank">興業銀行</a>
</td>
<td><a href=" target="_blank">郵政儲蓄</a>
</td>
</tr>
</table>
</div>
</div>
<div style="width:750px;margin:auto;margin-top:50px;" class="Noprint">
<div>幫助:點擊【打印】按鈕沒有反應。<span class="open helpSpan" onclick="wOpen()">>>>展開</span><span onclick="wClose()" class="close helpSpan" style="display:none;"><<<收起</span></div>
<div id="helpContent" style="display:none;">
<p>需要將本站點添加為信任站點。共分為三步。</p>
<p>第一步:打開IE瀏覽器的 Intenet選項</p>
<div><img src="<%=path%>/images/open_Intenet_ie8.jpg"/></div>
<p>或者</p>
<div><img src="<%=path%>/images/open_Intenet_ie11.jpg"/></div>
<p style="margin-top:20px;">第二步:添加信任站點</p>
<div><img src="<%=path%>/images/setXinren_ie11.jpg"/></div>
<p style="margin-top:20px;">第三步:允許控件運行</p>
<div><img src="<%=path%>/images/setActive.jpg"/></div>
</div>
</div>
<!--endprint-->
</body>
</html>
代碼中所需圖片如下:



