当前位置: 代码迷 >> Java Web开发 >> 200分求大伙儿解决jasperreport通过APPLET客户端打印
  详细解决方案

200分求大伙儿解决jasperreport通过APPLET客户端打印

热度:5921   发布时间:2016-04-10 23:56:14.0
200分求大家解决jasperreport通过APPLET客户端打印
本帖最后由 tangyu477 于 2012-07-10 09:01:30 编辑
jasperreport通过APPLET客户端打印,出现了报表样式丢失,
请问谁遇到并解决了呢,希望没遇到的,高手们也给分析分析,直接上代码好了、



Action


public String PrintStanding() throws Exception{

String querydate=request.getParameter("querydate");
String storeid=request.getParameter("storeId");

String storeStatus=request.getParameter("storeStatus");
String goodsType=request.getParameter("goodsType");
String goodsId=request.getParameter("goodsId");

String printUser=request.getParameter("printUser");
String StoreName=request.getParameter("StoreName");
System.out.println();

Map<String, Object> waremap=new HashMap<String, Object>();
waremap.put("goodsType", goodsType);
waremap.put("goodsId", goodsId);
waremap.put("storeid", storeid);
waremap.put("storeStatus", storeStatus);
List<WarehouseGoods> list=warehouseInService.printWareStanding(waremap);



Map<String, Object> parameter = new HashMap<String, Object>();  
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        parameter.put("QUERY_TIME",sdf.parse(querydate));
        parameter.put("CREATE_USER",printUser);
        parameter.put("STORE_NAME",StoreName);
   
        
        
        
        //对数据和打印模板进行填充
        response.setContentType("application/octet-stream");
        response.setBufferSize(8986000);
ServletOutputStream ouputStream = response.getOutputStream();
// JasperReport jrt = JasperCompileManager.compileReport(request.getRealPath(STANDING_PRINT_MODEL_FILE));// 编译报表格式

JRDataSource dataSource = new JRBeanCollectionDataSource(list);
JasperPrint jpt = JasperFillManager.fillReport(request.getRealPath(STANDING_PRINT_MODEL_FILE), parameter,dataSource);// 匹配数据源,生成JasperPrint
//JasperPrintManager.printReport(report, false);//此处为服务器打印,可以看见报表样式未丢失,但不符合需求,需客户端打印
//打印数据输出
ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
oos.writeObject(jpt);
oos.flush();
oos.close();
        
return null;
}



Applet




import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;

import javax.swing.JOptionPane;

import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.util.JRLoader;

public class JRPrinterApplet extends javax.swing.JApplet {

private URL url = null;
private JasperPrint jasperPrint = null;

/** Creates new form AppletViewer */
public JRPrinterApplet() {

}
public void init() {
String strUrl = getParameter("REPORT_URL");
if (strUrl != null) {
try {
url = new URL(getCodeBase(), strUrl);
} catch (Exception e) {
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
JOptionPane.showMessageDialog(this, swriter.toString());
}
} else {
JOptionPane.showMessageDialog(this,"init():Source URL not specified");
}
}

public void start() {
if (url != null) {
if (jasperPrint == null) {
try {
//System.out.println("进入start方法,即将下载pdf文件");
jasperPrint = (JasperPrint) JRLoader.loadObject(url);
//System.out.println("进入start方法,下载pdf文件完毕");
} catch (Exception e) {
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
JOptionPane.showMessageDialog(this, swriter.toString());
}
}
if (jasperPrint != null) {
final JasperPrint print = jasperPrint;
Thread thread = new Thread(new Runnable() {
public void run() {
try {
//System.out.println("进入start方法,即将打印pdf文件");
JasperPrintManager.printReport(print, false);
} catch (Exception e) {
StringWriter swriter = new StringWriter();
PrintWriter pwriter = new PrintWriter(swriter);
e.printStackTrace(pwriter);
JOptionPane.showMessageDialog(null,swriter.toString());
}
}
});
thread.start();
} else {
  相关解决方案