JSP页面实现循环打印

jsp+servlet+javabean 同时被 3 个专栏收录
8 篇文章 0 订阅
11 篇文章 0 订阅
16 篇文章 1 订阅

首先在页面上要有一个“打印按钮”,来触发这个打印操作:

调用choosePrint()方法:

// 打印操作
	var timer, win, recCount, rownum;
	function choosePrint() {
		rownum = 0;
		var records = grid.getSelectionModel().getSelections();// 获取多行
		recCount = records.length;
		var JSONString = "";
		record = records[rownum];
		showPrint(record);
		timer = setInterval(printSave, "500");
	}
	function printSave() {
		if (win.closed) {
			if (rownum >= recCount) {
				clearInterval(timer);
			} else {
				var records = grid.getSelectionModel().getSelections();
				record = records[rownum];
				showPrint(record)
			}
		}
	}
	function showPrint(record) {
			var Customername = record.get('Customername');
			var Curtype1 = record.get('Curtype1');
			var Amount1 = record.get('Amount1');
			var Curtype2 = record.get('Curtype2');
			var Amount2 = record.get('Amount2');
			var Businessnum = record.get('Businessnum');
			var Acnt1 = record.get('Acnt1');
			var Acnt2 = record.get('Acnt2');
			var Biztype = record.get('Biztype');
			var Pztype = record.get('Pztype');
			var Exrate = record.get('Exrate');
			var Bizid = record.get('Bizid');
			var Pzid = record.get('Pzid');
			var Id = record.get('Id');
			var Feetype = record.get('Feetype');
			var Curtype = record.get('Curtype');
			var Amount = record.get('Amount');

			JSONString = Customername + "," + Acnt1 + "," + Acnt2 + ","
					+ Biztype + "," + Pztype + "," + Businessnum + ","
					+ Curtype1 + "," + Amount1 + "," + Curtype2 + "," + Amount2
					+ "," + Exrate + "," + Bizid + "," + Pzid + "," + Id + ","
					+ Feetype + "," + Curtype + "," + Amount + ";";
			win = showJSWindow(
					'print.ered?reqCode=vorcharPrint&flag=Print&JSONString='
							+ JSONString, 600, 400);
		rownum++;
	}

/** 弹出窗口 */
function showJSWindow(url, width, height) {
	var pWidth = width ? width : document.body.clientWidth * 0.7;
	var pHeight = height ? height : 470;
	 var str = 'width=' + pWidth
			+ ',height=' + pHeight
			+ ',toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no';
	return window.open(url, '', str);
}



其中这段代码的意思为:
win = showJSWindow(
					'print.ered?reqCode=vorcharPrint&flag=Print&JSONString='
							+ JSONString, 600, 400);
打开一个jsp页面vocharPrint.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<title>结算打印</title>
<style type="text/css">
body {
	margin: 0px;
}

.printStyle td {
	BACKGROUND-COLOR: #FFFFFF;
	COLOR: black;
	FONT-FAMILY: 'Times New Roman';
	FONT-SIZE: 12pt;
}

.Noprint {
	DISPLAY: none;
}
</style>
<body>
	<form name="thisform" id="thisform" method="post">
		<br /> <br />
		<div style="width: 90%; hight: 80%">
			<table class="printStyle" width="95%" align="center" cellpadding="2"
				border="0">
				<%
					List printList2 = (List) request.getAttribute("printList2");
					for (Iterator iterator = printList2.iterator(); iterator.hasNext();) {
						HashMap printMap2 = (HashMap) iterator.next();
				%>
				<tr>
					<td>
						<div style="margin-left: 70%">
							日期:<span><%=printMap2.get("Printdate")%></span>
						</div>
					</td>
				</tr>
				<tr>
					<td>户名 :<%=printMap2.get("Customername")%>
					</td>
				</tr>
				<tr>
					<td>账号:<%=printMap2.get("Acnt1")%>
					</td>
				</tr>
				<tr>
					<td>业务类型:<%=printMap2.get("Printtype") != null ? printMap2
						.get("Printtype") : ""%>
					</td>
				</tr>
				<tr>
					<td>LC编号:<%=printMap2.get("Businessnum")%>
					</td>
				</tr>
				<tr>
					<td>外汇金额:<%=printMap2.get("Curtype2")%>    <%=printMap2.get("Amount2")%>
					</td>
				</tr>
				<tr>
					<td>合同号:<%=printMap2.get("Contrno") != null ? printMap2
						.get("Contrno") : ""%>
					</td>
				</tr>
				<%
					if (printMap2.get("Feetype") != null
								|| printMap2.get("Feetype") != "") {
							if (printMap2.get("Feetype") == "F001") {
				%>
				<tr>
					<td>手续费:<%=printMap2.get("Curtype")%>    <%=printMap2.get("Amount")%>
					</td>
				</tr>
				<%
					}
							if (printMap2.get("Feetype") == "F002") {
				%>
				<tr>
					<td>电报费:<%=printMap2.get("Curtype")%>    <%=printMap2.get("Amount")%>
					</td>
				</tr>
				<%
					}

						} else {
				%>
				<tr>
					<td>汇率:<%=printMap2.get("Exrate")%>
					</td>
				</tr>
				<%
					}
				%>
				<tr>
					<td>备注:</td>
				</tr>
				<tr>
					<td>
						<div style="float: left">合计:</div>
						<div style="margin-left: 30%; float: left;"><%=printMap2.get("Curtype1")%>    <%=printMap2.get("Amount1")%></div>
					</td>
				</tr>
				<%
					}
				%>
			</table>
		</div>
		<div style="margin-top: 30px;">
			<table width="98%">
				<tr>
					<td width="25%">记账:</td>
					<td width="25%">复核:</td>
				</tr>
			</table>
		</div>
	</form>
</body>

<script type="text/javascript">
	window.onload = function() {
		window.print();
		window.close();
	}
</script>
</html>



  • 2
    点赞
  • 0
    评论
  • 1
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页

打赏作者

不讲理的胖子

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值