2013-07-12 100 views
0

我在我的項目上使用struts和jasper報告,現在我遇到了問題,每當我嘗試打印報告時,打印機對話框出現在服務器機器上,我想要它在客戶端沒有以任何格式導出報告,如何解決這個問題,請任何人知道幫助我,這是緊急的。賈斯珀報告打印在客戶端沒有生成報告

回答

2

我試過下面的代碼sta,它對我來說工作得很好。

步驟1: 在鹼jsp的(report.jsp)

INPUT TYPE = 「隱藏」 名稱= 「的contextPath」 值= 「<%= request.getContextPath()%>」 ID =」的contextPath「/>

步驟2: 在includesed JS(report.js)

var contextPath=document.getElementById("contextPath").value; 
var url=contextPath+"/generateRecptReport.do?method=generateRecptReport; 
popupWin= window.open(url,'Report','menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=1, height=1 left=0, top=0'); 

步驟3 在struts-config.xml文件

<action path="/generateRecptReport" scope="request" parameter="method" type="com.cm.actions.ReceiptMakerProcessAction"> 
</action> 

* *行動(Java代碼)(ReceiptMakerProcessAction.java)

public ActionForward generateRecptReport(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception 
{ 
logger.info("In generateRecptReport");   
     String p_company_logo=getServlet().getServletContext().getRealPath("/")+"reports/logo.bmp"; 
     String reportPath="/reports/MSSQLREPORTS/"; 
     String reportName="receiptMemoReport";   
     ReportsDAO reportdao = (ReportsDAO)DaoImplInstanceFactory.getDaoImplInstance(ReportsDAO.IDENTITY); 
     logger.info("Implementation class: "+reportdao.getClass()); 
     reportName=reportdao.getReceiptReportName(); 
     if(CommonFunction.checkNull(reportName).trim().equalsIgnoreCase("")) 
      reportName="receiptMemoReport";    

     Connection connectDatabase = ConnectionDAO.getConnection();  
     Map<Object,Object> hashMap = new HashMap<Object,Object>(); 
     hashMap.put("p_company_logo",p_company_logo); 
     hashMap.put("IS_IGNORE_PAGINATION",true); 
     try 
     { 
      InputStream reportStream = getServlet().getServletConfig().getServletContext().getResourceAsStream(reportPath+reportName+".jasper"); 
      JasperPrint jasperPrint = null; 
      PrintWriter out=response.getWriter(); 
      out.append("<head><script type='text/javascript' src='"+request.getContextPath()+"/js/report/report.js'></script></head>"); 
      out.append("<body onLoad='self.print();self.close()'></body>");  
      response.setContentType("text/html");  
      String htmlReportFileName=reportName+".html"; 
      JRHtmlExporter exporter = new JRHtmlExporter();  
      request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);  
      exporter.setParameter(JRHtmlExporterParameter.OUTPUT_WRITER, out); 
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); 
      exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN ,Boolean.FALSE); 
      exporter.setParameter(JRHtmlExporterParameter.IGNORE_PAGE_MARGINS ,Boolean.TRUE); 
      exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.FALSE); 
      exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE); 
      exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE); 
      exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML,""); 
      exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, response.getWriter()); 
      float f1=1.2f; 
      exporter.setParameter(JRHtmlExporterParameter.ZOOM_RATIO ,f1); 
      exporter.exportReport();      
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
     finally 
     { 
      ConnectionDAO.closeConnection(connectDatabase, null); 
      hashMap.clear(); 
     } 
     return null; 
    } 

希望這將是碧玉報告打印有幫助的步驟4 在客戶端沒有產生報告