Jump to content
We've recently updated our Privacy Statement, available here ×

Probem in passing parameter to the report


emmadi

Recommended Posts

Hi

i am trying to generate a pdf report by passing groupname to the jrxml file

here i am using pdf.jsp to pass the value

String groupname =request.getParameter("groupname");
String file = request.getParameter("jr");
          String fileloc = file+".jrxml";
         System.out.println("filelocation-->"+fileloc);
           
             HashMap parameter = new HashMap();
             JasperPrint jasperPrint = null;
              Connection connection = null;
            // parameter.put("gname",groupname);
              parameter.put("gname","employee");
            
      File reportFile=new File(application.getRealPath(fileloc));
      JasperDesign jasperDesign=JRXmlLoader.load(reportFile.getPath());
      JasperReport jasperReport=JasperCompileManager.compileReport(jasperDesign);
          
      String dbproperties=application.getRealPath("Database");
      FileInputStream fis=new FileInputStream(dbproperties);
      Properties props=new Properties();
      props.load(fis);
      String driver=props.getProperty("driver");
      String url="jdbc:mysql://localhost/harika" ;
      String username="root" ;
      String password="touch" ;
     
      Class.forName(driver);
      Connection jdbcConnection=DriverManager.getConnection(url,username,password);
      byte[] bytes=JasperRunManager.runReportToPdf(jasperReport,null,jdbcConnection);
      response.setContentType("application/pdf");
      ServletOutputStream outputStream=response.getOutputStream();
      outputStream.write(bytes,0,bytes.length);
      outputStream.flush();
      outputStream.close();
     
      }catch(Exception e)
      {out.println(e); }
      %>
     
      </body>
    </html> 
  

and modifications done in jrxml are

<parameter name="gname" isForPrompting="false" class="java.lang.String"/>
    <queryString><![CDATA[select * from user_account where groupname=$P{gname}]]></queryString>

 

but i dint get any errors while i am compiling but  there is no result

i am getting a blank pdf report

Please some body help me

thanku

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 you have to do 2 modifications

1.  

<parameter name="gname" isForPrompting="false" class="java.lang.String" />

Change the above line as 

<parameter name="gname" isForPrompting="true" class="java.lang.String" />

2.

 byte[] bytes=JasperRunManager.runReportToPdf(jasperReport,null,jdbcConnection);

Change the above line as

 byte[] bytes=JasperRunManager.runReportToPdf(jasperReport, parameter,jdbcConnection);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...