how can I print the same thing in jasperreport

0

my jasperreport have connect mysql.

Now I want to print the label

I hope I can choose how much label I want to print

but always fail 

I just can print

but I want to print( I can assign each number when I print customer 

this is my code

 

<%@ include file = "db.jsp"%> 
<!DOCTYPE html>
<html>
   <body>
<div class="container">
 
  <form action = "index.jsp" method = "post">
   <center ><input type=checkbox name='b' value="A0000"><font size="5">A customer</font></input>
     <input type="text" name="num" id="num" value="0"/><font size="5"></font>
     <center ><input type=checkbox name='b' value="A0001"><font size="5">B customer</font></input>
     <input type="text" name="num2" id="num2" value="0"/><font size="5"></font>
   </center>
 
   <center>  <input type = "submit" name = "index" value = "送出" class="btn btn-success"> 
  </form>
</div>
<%   
      String[] b=request.getParameterValues("b");
 
        int i;
         if(request.getParameter("index") != null && b!=null)
           {  sql = "select* from send where   "; 
           //////
            int number=Integer.parseInt(request.getParameter("num"));
            int number2=Integer.parseInt(request.getParameter("num2"));
           if(number>0 ){
           for(i=0;i<number;i++)
                {
             sql=sql+   "  c_id ='" + "A0000" + "' "; 
                 sql=sql+   "  or  "; 
                }
           }
           if(number2>0 ){
           for(i=0;i<number2;i++)
                {
             sql=sql+   "  c_id ='" + "A0001" + "' "; 
                 sql=sql+   "  or  "; 
                }
           }
 
          session.setAttribute("sql", sql);
                  response.sendRedirect("show.jsp");
      } 
 
    %> 
 
    </body>
</html>

show.jsp

<% 
 
       String Lang3="";
      Object sql1=session.getAttribute("sql"); 
 
       if(sql1!=null){Lang3=sql1.toString();}
 
     String Lang3="";
      Object sql1=session.getAttribute("Lang2"); 
 
       if(sql1!=null){Lang3=sql1.toString();}
 
        ResultSet rs = stmt.executeQuery(sql1);  
           File reportFile = new File(application.getRealPath("/report/r.jasper"));
            Map parameters = new HashMap();
           JRDataSource dataSource = new JRResultSetDataSource(rs);
             byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, dataSource); 
            response.setContentType("application/pdf");
            response.setContentLength(bytes.length);
            ServletOutputStream outStream = response.getOutputStream();
            outStream.write(bytes, 0, bytes.length);
            outStream.flush();
            outStream.close(); 
            rs.close();
 
 
%> 

cool3690's picture
Joined: Sep 18 2018 - 12:52am
Last seen: 8 months 2 days ago

2 Answers:

0

Just put your LabelContent from current (probably) detail-band into a new SubReport or just a simple ListElement and use as SubReportDataSource- or List-DataSource-Expression:

new JREmptyDataSource($F{NumberOfLabelsForRecord})

where the number of labels for current record is in the sample field "NumberOfLabelsForRecord".

The other data from actual record you could pass as Parameter down to the SubReport or List

So you needn't duplicate your records outside the report just to repeat each record individually

hth + regards

C-Box

C-Box's picture
2157
Joined: Jul 19 2006 - 5:58pm
Last seen: 2 days 17 hours ago
0

You'll need to modify so there's be multiple same rows in the datasource.

hozawa's picture
52592
Joined: Apr 24 2010 - 4:31pm
Last seen: 5 months 1 week ago
Feedback
randomness