Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/zyqwst/PrintServer
Browse files Browse the repository at this point in the history
  • Loading branch information
zyqwst committed Sep 19, 2017
2 parents 1f8651e + 1775e6c commit 823a50d
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/confinement">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
Expand Down
3 changes: 3 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/com/albert/servlet/BaseServlet.java=UTF-8
encoding/src=UTF-8
7 changes: 5 additions & 2 deletions WebContent/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<body class="container">
<div class="jumbotron">
<h2>Web打印控件样例</h2>
服务端打印DEMO采用简单的Servlet 3.0。本地打印DEMO是基于Blade的轻量级MVC框架,访问端口9000。
服务端打印DEMO采用简单的Servlet 3.0。本地打印客户端通过自定义URL Protocol调用本地java程序。
亲测ie9,10,11;chrome,火狐等浏览器均支持。
<p></p>
<a id="printBtn" class="btn btn-primary" onclick="print_server('zjd')">点击打印</a>
<a class="btn btn-danger" href="ViewerJS/#../bill.xls">预览</a>
Expand All @@ -23,6 +24,8 @@ <h2>Web打印控件样例</h2>
<script type="text/javascript">

function print_server(method_name) {
var platform = navigator.platform;
alert(platform);
$.ajax({
url : "print?method=" + method_name,
dataType : "json",
Expand All @@ -41,7 +44,7 @@ <h2>Web打印控件样例</h2>
}

function local_print(data) {
location.href='sx-print:'+"http://192.168.1.6/PrintServer/print?method=printdata&&key="+data.content;
location.href='albertprint:'+'http://127.0.0.1/PrintServer/'+'print?method=printdata&&key='+data.content;
}
</script>

Expand Down
7 changes: 7 additions & 0 deletions src/com/albert/servlet/BaseServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.albert.servlet;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Method;

Expand Down Expand Up @@ -66,4 +67,10 @@ public void write(HttpServletResponse resp, ResponseEntity r) throws IOException
out.flush();
out.close();
}
public void writeObject(HttpServletResponse resp, ResponseEntity r) throws IOException{
ObjectOutputStream oos = new ObjectOutputStream(resp.getOutputStream());
oos.writeObject(r);
oos.flush();
oos.close();
}
}
7 changes: 3 additions & 4 deletions src/com/albert/servlet/PrintServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void zjd() throws ServletException, IOException {
String key = UUID.randomUUID().toString();
System.out.println(key);
Cache.Instance().put(key, ResponseEntity.success(xml, json));
write(resp, ResponseEntity.success(key));
writeObject(resp, ResponseEntity.success(key));
} catch (Exception e) {
e.printStackTrace();
write(resp,ResponseEntity.failed(e.getMessage()));
Expand All @@ -64,11 +64,10 @@ public void printdata() throws IOException {
Object obj = Cache.Instance().get(req.getParameter("key"));
if(obj==null) throw new Exception("未找到打印数据");
ResponseEntity r = (ResponseEntity)obj;
System.out.println(r.getContent());
write(resp, r);
writeObject(resp, r);
} catch (Exception e) {
e.printStackTrace();
write(resp,ResponseEntity.failed(e.getMessage()));
writeObject(resp,ResponseEntity.failed(e.getMessage()));
}
}
}
Binary file added src/demo.jasper
Binary file not shown.
32 changes: 29 additions & 3 deletions src/demo.jrxml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-03-19T12:00:36 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="demo2" pageWidth="680" pageHeight="396" columnWidth="640" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c175de4-1a12-46c8-ac5f-3a3a1658275f">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="myJson"/>
<property name="com.jaspersoft.studio.unit." value="mm"/>
Expand All @@ -12,6 +10,9 @@
<property name="com.jaspersoft.studio.unit.rightMargin" value="mm"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="mm"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="mm"/>
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="json">
<![CDATA[]]>
</queryString>
Expand Down Expand Up @@ -53,7 +54,7 @@
</band>
</pageHeader>
<columnHeader>
<band height="30" splitType="Stretch">
<band height="128" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="3c1c7bf5-e051-4c71-a03b-f2dcf8fb2f91"/>
<box topPadding="0" leftPadding="0" bottomPadding="0" rightPadding="0">
Expand Down Expand Up @@ -98,6 +99,31 @@
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[日期]]></text>
</staticText>
<xyLineChart>
<chart>
<reportElement x="415" y="0" width="200" height="100" printWhenGroupChanges="Group1" uuid="7cfe0b02-612e-431d-b41d-f2fedcd249ad"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset resetType="Group" resetGroup="Group1"/>
<xySeries>
<seriesExpression><![CDATA[$F{code}]]></seriesExpression>
<xValueExpression><![CDATA[$F{name}]]></xValueExpression>
<yValueExpression><![CDATA[$F{creDate}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</linePlot>
</xyLineChart>
</band>
</columnHeader>
<detail>
Expand Down

0 comments on commit 823a50d

Please sign in to comment.