1.java后端的servlet代码:
BbDyServlet.java:
package com.topinfo.upload;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.topinfo.entity.BtBb;
import com.topinfo.entity.BtDjsfbb;
import com.topinfo.entity.BtLzbg;
import com.topinfo.entity.BtSgjl;
import com.topinfo.entity.BtSgtjbb;
import com.topinfo.entity.BtXzcfbb;
import com.topinfo.entity.BtXzcfbbmx;
import com.topinfo.entity.BtYhbb;
import com.topinfo.entity.BtZffabb;
import com.topinfo.entity.BtZffabbmx;
import com.topinfo.entity.BtZfqkbb;
import com.topinfo.entity.BtZfqkbbmx;
import com.topinfo.entity.BtZzqyjb;
import com.topinfo.entity.BtZfbb;
import com.topinfo.libs.QueryCondition;
import com.topinfo.libs.QueryList;
import com.topinfo.service.AqscbzhService;
import com.topinfo.service.BbglService;
import com.topinfo.service.HyjgService;
import com.topinfo.service.LzbgService;
import com.topinfo.service.QycxService;
import com.topinfo.service.SgglService;
import com.topinfo.service.TDictionaryService;
import com.topinfo.service.TjfxService;
import com.topinfo.service.ZfjcService;
import com.topinfo.service.entity.AqscTjfx;
import com.topinfo.service.entity.CxfjHyDjTj;
import com.topinfo.service.entity.CxfjTjaxzjdf;
import com.topinfo.service.entity.Hyjgtjfx;
import com.topinfo.service.entity.WhScjylxTj;
import com.topinfo.service.entity.WhWhplxTj;
/**
* Servlet implementation class ZdhyyhbbDyServlet
*/
@WebServlet("/ZdhyyhbbDyServlet")
public class BbDyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BbDyServlet() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
private List<BtYhbb> yhbb ;
private List<BtYhbb> yhbbhz ;
private List<BtZfbb> zfbb;
private List<BtZfbb> zfbbhz;
private List<BtZfqkbbmx> zfqkmx;
private List<BtZfqkbbmx> zfqkhz;
private List<BtDjsfbb> sfbb;
private List<BtDjsfbb> sfbbhz;
private List<BtSgtjbb> sgbb;
private List<BtSgtjbb> sgbbhz;
private BtZfqkbb bb_zfqk;
private List<BtXzcfbbmx> xzcfmx;
private List<AqscTjfx> aqsctjfx;
private List<CxfjTjaxzjdf> fjqydq;
private List<CxfjHyDjTj> fjqyhy;
private List<BtSgjl> sgyb;
private List<WhWhplxTj> whplxs;
private List<WhScjylxTj> scjylxs;
//执法方案
private List<BtZffabbmx> zffamxbb;
private BtZffabb fabb;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//services if()
String type = request.getParameter("type");
//重点行业隐患打印
if(type!=null&&type.equals("zdhybb")){
String url = printZdhyyhbbDy(request,response);
request.setAttribute("yhbb",yhbb);
request.setAttribute("bb", bb);
request.getRequestDispatcher(url).forward(request,response);
}
。。。。。。
public String printZdhyyhbbDy(HttpServletRequest request, HttpServletResponse response){
//查数据 printList
BbglService impl = (BbglService)ac.getBean("bbglServiceImpl");
TDictionaryService dictionary = (TDictionaryService)ac.getBean("TDictionaryServiceImpl");
Integer nf=Integer.valueOf(request.getParameter("nf"));
Integer yf=Integer.valueOf(request.getParameter("yf"));
String tbdwdm=request.getParameter("tbdw");
Integer bblx=Integer.valueOf(request.getParameter("bblx"));
Integer hz=Integer.valueOf(request.getParameter("hz"));
yhbb =impl.findAllBtYhbbmxByNfYf(nf, yf, tbdwdm, bblx, hz);
bb=impl.getTbXxByYearMonth(nf, yf, tbdwdm, bblx, hz);
bb.setBbTbdw(dictionary.getParentNameByDM(bb.getBbTbdw()));
return "zdhyyhbbDy.jsp";
}
2.jsp打印界面:
zdhyyhbbDy.jsp:
<%@ page language="java" import="java.util.*,com.topinfo.entity.*,java.text.SimpleDateFormat" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>矿山、危化、烟花爆竹、冶金等行业和领域安全生产隐患排查治理情况报表</title>
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>
<script type="text/javascript">
var hkey_key;
var hkey_root="HKEY_CURRENT_USER";
var hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
//设置网页打印的页眉页脚为空
function pagesetup_null()
{
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,"");
}
function print(){
pagesetup_null();
document.all.WebBrowser.ExecWB(6,1);
}
</script>
</head>
<body >
<center class="Noprint">
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=页面设置 οnclick=document.all.WebBrowser.ExecWB(8,1)>
<input type=button value=打印预览 οnclick=document.all.WebBrowser.ExecWB(7,1)>
<input type=button value=打印 οnclick=document.all.WebBrowser.ExecWB(6,1)>
<br/>
<table style="color:red;font-size:10px;">
<tr><td style="color:red;">*请在IE浏览器中进行打印</td></tr>
<tr><td style="color:red;">*请降低安全级别 保证打印控件的安装</td></tr>
<tr><td style="color:red;">*可采用鼠标右键进行页面打印 </td></tr>
</table>
</font>
</center>
<center>
<h3>矿山、危化、烟花爆竹、冶金等行业和领域安全生产隐患排查治理情况报表</h3>
</center>
<%
BtBb bb=(BtBb)request.getAttribute("bb");
String nf;
String yf;
String rq;
if(bb.getBbTbrq()==null){
nf="";
yf="";
rq="";
}else{
Date date=bb.getBbTbrq();
SimpleDateFormat sn=new SimpleDateFormat("yyyy");
nf=sn.format(date);
SimpleDateFormat sy=new SimpleDateFormat("MM");
yf=sy.format(date);
SimpleDateFormat t=new SimpleDateFormat("dd");
rq=t.format(date);
}
%>
<table width=968 align=center>
<tr>
<td width=122>填报单位(章): </td>
<td width=580><%= bb.getBbTbdw() %></td>
<td width=55>截止到</td>
<td width=40><%= bb.getBbNf() %></td>
<td width=20>年</td>
<td width=40><%= bb.getBbYf() %></td>
<td width=40>月底</td>
</tr>
</table>
<table cellspacing=0 cellpadding=0 width=968 align=center align=center style="font-size:12px;border=1 solid black;border-collapse:collapse;border-width:1px 0 0 1px;" >
<tr>
<td width=210 nowrap rowspan=5 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">行业和领域
</td>
<td width=209 nowrap colspan=4 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>
排查一般隐患</p>
</td>
<td width=549 nowrap colspan=10 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>排查重大隐患</p>
</td>
</tr>
<tr>
<td width=67 nowrap rowspan=3 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>排查</p>
<p align=center>单位数</p>
</td>
<td width=45 nowrap rowspan=3 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>隐患数</p>
</td>
<td width=49 nowrap rowspan=3 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>已经</p>
<p align=center>整改数</p>
</td>
<td width=47 nowrap rowspan=3 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>整改率</p>
</td>
<td width=150 nowrap colspan=3 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>排查治理重大隐患</p>
</td>
<td width=399 nowrap colspan=7 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>列入治理计划的重大隐患
</p>
</td>
</tr>
<tr>
<td width=52 nowrap rowspan=2 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>重大</p>
<p align=center>隐患数</p>
</td>
<td width=49 nowrap rowspan=2 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>已整改</p>
<p align=center>销号数</p>
</td>
<td width=49 nowrap rowspan=2 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>整改率</p>
</td>
<td width=56 nowrap rowspan=2 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>重大</p>
<p align=center>隐患数</p>
</td>
<td width=287 nowrap colspan=5 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>其中</p>
</td>
<td width=56 nowrap rowspan=2 style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>累计落实</p>
<p align=center>治理资金</p>
</td>
</tr>
<tr>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>落实治理</p>
<p align=center>目标任务</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>落实治理</p>
<p align=center>经费物资</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>落实治理</p>
<p align=center>机构人员</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>落实治理</p>
<p align=center>时间要求</p>
</td>
<td width=63 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>落实安全措</p>
<p align=center>施应急预案</p>
</td>
</tr>
<tr>
<td width=67 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(家)</p>
</td>
<td width=45 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=49 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=47 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(%)</p>
</td>
<td width=52 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>
(项)</p>
</td>
<td width=49 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=49 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(%)</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=63 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(项)</p>
</td>
<td width=56 nowrap style="border:solid black;border-width:0 1px 1px 0;padding:2px;">
<p align=center>(万元)</p>
</td>
</tr>
<%
List<BtYhbb> list=(List<BtYhbb>)request.getAttribute("yhbb");
for(int k=0;k<list.size();k++){
%>
<tr>
<td width=210 style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getYhbbHyly() %></td>
<td width=67 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getYhbbYbyhpcs() %></td>
<td width=45 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute428() %></td>
<td width=49 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute429() %></td>
<td width=47 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute430() %></td>
<td width=52 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute431() %></td>
<td width=49 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute432() %></td>
<td width=49 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute433() %></td>
<td width=56 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute434() %></td>
<td width=56 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute435() %></td>
<td width=56 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute436() %></td>
<td width=56 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute437() %></td>
<td width=56 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute438() %></td>
<td width=63 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute439() %></td>
<td width=56 align=center style="border:solid black;border-width:0 1px 1px 0;padding:2px;"><%= list.get(k).getAttribute440() %></td>
</tr>
<%
}
%>
</table>
<table width=968 align=center>
<tr>
<td width=150 align=left>单位负责人(签字):</td>
<td width=130 align=left><%= bb.getBbDwfzr()!=null?bb.getBbDwfzr():"" %></td>
<td align=left>填表人(签字):</td>
<td width=160 align=left><%= bb.getBbTbr()!=null?bb.getBbTbr():"" %></td>
<td width=85 align=left>联系电话:</td>
<td width=90 align=left><%= bb.getBbLxdh()!=null?bb.getBbLxdh():"" %></td>
<td align=left>填报日期:</td>
<td><%= nf %></td>
<td align=left>年</td>
<td><%= yf %></td>
<td align=left>月</td>
<td><%= rq %></td>
<td align=left>日</td>
</tr>
</table>
</body>
</html>
通过这2个文件变可实现在felx中打印了。