7 Replies Latest reply: May 3, 2011 1:58 AM by EJP RSS

    In mozilla version 4.0 sometimes pdf is generated

    771916
      Hi,
      I am using jdeveloper11.1.1.2.0.In Mozilla version 3.6.16 ,I want to generate PDF Report, its working fine.
      but in Mozilla version 4.0 sometimes pdf report is working and sometimes pdf report is not generated.
      So what is the problem for resolving this issue.

      Thanks&Regards
      Anup
        • 1. Re: In mozilla version 4.0 sometimes pdf is generated
          802316
          Can you post some of your Java code to reproduce this problem?
          • 2. Re: In mozilla version 4.0 sometimes pdf is generated
            771916
            Hi,
            I am using servlet2.5 jar file jasper report3.6jar file.
             public String getReportURL() {
                    FacesContext facesContext = FacesContext.getCurrentInstance();
                    ExternalContext externalContext =
                    facesContext.getExternalContext();
                    HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
                    String strUrl = request.getRequestURL() + "";
                    int iPosition = strUrl.indexOf("/faces/");
                    strUrl = strUrl.substring(0,iPosition+6) + "/doReport";
                    this.reportURL = strUrl;
                    return reportURL;
                }
                
                public String runReport() {
                
                        try {
                            return "dialog:ReportDialog";
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            System.out.println(ex);
                            return null;
                        }
                }
            Edited by: EJP on 2/05/2011 22:57: added code tags. Please use them.
            • 3. Re: In mozilla version 4.0 sometimes pdf is generated
              802316
              The problem appears to be that the report is not always generated under a particular browser. Can you log the incoming request as see what is different about it?

              BTW: how can returning a string literal throw an exception?
              • 4. Re: In mozilla version 4.0 sometimes pdf is generated
                771916
                Hi,
                Actually i m not unable to generate the pdf report in Mozilla version4.
                Sometimes PDF Report Data is generated and sometimes PDF Report Data is blank.but In Old version mozilla3.6 everything is working.
                So can i know what is the issue for latest mozilla verson 4.0.

                let me know what is the issue...

                Thanks
                Anup

                1: open a dialog , and get url of servlet
                <af:commandButton text="Dialog Report" id="cbdialogReport"
                action="#{ReportBean.cbdialogReport_action}"
                useWindow="true" windowHeight="1000"
                windowWidth="1100"/>
                public String cbdialogReport_action() {
                try {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                ExternalContext externalContext =
                facesContext.getExternalContext();
                HttpServletRequest request = (HttpServletRequest)externalContext.getRequest();
                String strUrl = request.getRequestURL() + "";
                int iPosition = strUrl.indexOf("/faces/");
                strUrl = strUrl.substring(0,iPosition+6) + "/doreport";
                this.reportURL = strUrl;
                System.out.println("strUrl=" + strUrl); 
                //System.out.println("request.getRequestURI()= " + request.getRequestURI()); 
                return "dialog:ReportDialog";
                } catch (Exception ex) {
                System.out.println(ex);
                return null;
                }
                }
                2:diaolog
                <?xml version='1.0' encoding='UTF-8'?>
                <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
                <jsp:directive.page contentType="text/html;charset=UTF-8"/>
                <f:view>
                <af:document id="d1">
                <af:form id="f1">
                <af:panelStretchLayout id="psl1">
                <f:facet name="bottom"/>
                <f:facet name="center">
                <af:inlineFrame id="if1"
                source="#{ReportBean.reportURL}"/>
                </f:facet>
                <f:facet name="start"/>
                <f:facet name="end"/>
                <f:facet name="top"/>
                </af:panelStretchLayout>
                </af:form>
                </af:document>
                </f:view>
                </jsp:root>
                3: create a serlet
                package com.pansoft.myerp.servlet;
                
                import com.pansoft.myerp.view.Function;
                
                import java.io.File;
                import java.io.IOException;
                import java.io.InputStream;
                import java.io.OutputStream;
                import java.io.PrintWriter;
                
                import java.sql.Connection;
                
                import javax.faces.context.ExternalContext;
                import javax.faces.context.FacesContext;
                
                import javax.servlet.*;
                import javax.servlet.http.*;
                
                import net.sf.jasperreports.engine.JasperRunManager;
                
                public class doReport extends HttpServlet {
                private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
                
                public void init(ServletConfig config) throws ServletException {
                super.init(config);
                }
                
                /**Process the HTTP doGet request.
                */
                public void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException,
                IOException {
                try
                {
                FacesContext facesContext = FacesContext.getCurrentInstance();
                ExternalContext externalContext =
                facesContext.getExternalContext();
                //String strUrl = request.getRequestURL() + "";
                //System.out.println("URL: " + strUrl); 
                response.setContentType("application/pdf");
                response.addHeader("Content-Type", "application/pdf");
                //response.setHeader("Content-Type", "application/pdf");
                //response.addHeader("Content-Disposition", "inline;filename=Report.pdf");
                Function function = new Function();
                Connection conn = function.getCurrentConnection();
                OutputStream outputStream = response.getOutputStream();
                InputStream reportStream = externalContext.getResourceAsStream("/Report/rptChar.jasper");
                JasperRunManager.runReportToPdfStream(reportStream, outputStream, null, conn);
                outputStream.flush();
                outputStream.close();
                //facesContext.responseComplete(); 
                }catch(Exception ex) {
                System.out.println("doGet():" + ex);
                }
                
                }
                }
                Edited by: EJP on 2/05/2011 22:59: added { code } tags ...
                • 5. Re: In mozilla version 4.0 sometimes pdf is generated
                  EJP
                  private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
                  So you're writing PDF but telling the browser the content-type is HTML.

                  So make up your mind.
                  • 6. Re: In mozilla version 4.0 sometimes pdf is generated
                    771916
                    Hi,
                    I have change also response.setContentType("text/pdf"); and private static final String CONTENT_TYPE = "text/pdf; charset=UTF-8"; but i m getting same problem.
                    Blank PDF report data is generated...Sometimes pdf report data is generated ..

                    Thanks
                    Anup
                    • 7. Re: In mozilla version 4.0 sometimes pdf is generated
                      EJP
                      So sometimes Jasper is generating an empty report. So investigate that. This is no longer a Java question, it is a Jasper Reports question.