日期:2014-05-17 浏览次数:20704 次
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; }
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) {