cool3690 Posted March 20, 2019 Share Posted March 20, 2019 my jasperreport have connect mysql.Now I want to print the labelI hope I can choose how much label I want to printbut always fail I just can printbut 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]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();%> [/code] Link to comment Share on other sites More sharing options...
hozawa Posted March 20, 2019 Share Posted March 20, 2019 You'll need to modify so there's be multiple same rows in the datasource. Link to comment Share on other sites More sharing options...
Solution C-Box Posted March 20, 2019 Solution Share Posted March 20, 2019 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 ListSo you needn't duplicate your records outside the report just to repeat each record individuallyhth + regardsC-Box Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now