Jump to content
Changes to the Jaspersoft community edition download ×

how can I print the same thing in jasperreport

Go to solution Solved by C-Box,

Recommended Posts

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>[/code]


<%         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();%> [/code]


Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

  • Solution

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})[/code]

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


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...