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

HBK32

Members
  • Posts

    45
  • Joined

  • Last visited

HBK32's Achievements

Enthusiast

Enthusiast (6/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Collaborator Rare

Recent Badges

0

Reputation

  1. springilu Wrote: I would look at your report like it will always contain even number of pages the 2nd page will be address and all the other even numbered pages will be blank. The odd numbered pages will be the regular report contents. Once again thanks. How can I handle printing of this ? only 1st page should print duplex means two sided/flipside. Other pages should print normally means not duplex or two sided. As I mentioned earlier "Question is how can I handle printing of the first page i.e. two sided(flipside/duplex) from application or setting in report template ? As user will print is with default printer settings. How can I handle from application or report template setting ? e.g. report will have 4 pages. Now 1st page should print two side(duplex) conetent on front & address on the back of 1st page & other pages i.e. 2,3 & 4 should be single sided." Will appreciate your earliest response. Regards.
  2. springilu Wrote: I would insert a subreport for address into the details section conditionally. The condition would be insert sub report when the page number is 2. Thanks a lot for the response. My requirement is such that only 1st page should be two sided i.e. content on the front & address on the back of 1st page. I can achieve that as per your suggestion. But other pages should come one sided only as normally. Question is how can I handle printing of the first page i.e. two sided(flipside) from application or setting in report template ? As user will print is with default printer settings. How can I handle from application or report template setting ? e.g. report will have 4 pages. Now 1st page should print two side(duplex) conetent on front & address on the back of 1st page & other pages i.e. 2,3 & 4 should be single sided. Will greatly appreciate your earliest response. Regards.
  3. Hello, I have a requirement where I have to develop report which will have multiple pages. Now in that I need to print address on the back side(flipside) of the first page only not all pages. Means 1st page should have report content on the front side & address on the back side of the first page. How can I achieve this ? I am using iReport & jasper reports 1.3.0 version. I will really appreciate your earliest help/response on this. Regards.
  4. swood Wrote: You can create a set of parameters that do this. <parameter name="parameter1" class="java.lang.String"/> <parameter name="parameter2" class="java.lang.String"/> <parameter name="queryExpression" class="java.lang.String"> <defaultExpression>if both parameters entered, generate "columnName between ${parameter1} and ${parameter2} else generate "1=1" </defaultExpression> </parameter> <queryString> ... where $P!{queryExpression} </queryString> Sherman Jaspersoft Hello Sherman, Thanks a lot for the response. Please correct me if understand wrong here. Let me know following right or wrong. If its wrong can you plz correct it ? <parameter name="param1" class="java.lang.String"/> <parameter name="param2" class="java.lang.String"/> <parameter name="queryExpression" class="java.lang.String"> // following defaultExpression is for the parameter queryExpression <defaultExpression> ($P{param1} != null && $P{param}!=null) ? "Column_Name BETWEEN $P{param1} AND {param2}" : " 1 = 1 " </defaultExpression> What is the meaning of generate(i.e. generate "1=1") in your code ? I will greatly appreciate your response. Thanks.
  5. Hello, Can anyone tell me how to use BETWEEN clause in where clause of JasperServer report? e.g. there are two input(textbox) control to enter value which is NOT manadatory means its optional.Suppose user enter 10 in one textbox & 500 in second textbox then it should come as COLUMN_NAME BETWEEN 10 AND 500. If user don't enter anything then it should replace BETWEEN clause with 1=1 I will greatly appreciate your response. Thanks.
  6. lshannon wrote: Using subreports is a good way to query more than one datasource since the datasource expression for the subreport can be a JDBC Connection (which can be passed in as a parameter to the main report at fill time) or a JRDataSource object (which can be created in a separate java class). Hello, Thanks a lot for the response. In my case, master report query is against SQL server DB & subreport query is against Oracle DB. So in that case I need to open two DB connections in JSP. SQL server DB connection will go to master report at fill time & Oracle DB connection for subreport need to pass as a parameter to master report at fill time. I have defined one parameter with type of java.sql.Connection in master report for the oracle DB connection for subreport. this very same parameter is set as Data Source Expression in the subreport element of master report. Master report & sub report will have their own queries & there will be a common field with same data type & value from master report which will connect query in the subreport. e.g subreport query will be select * from test where dept_id = $P{MasterReportDept_ID} Please find attached JSP & JRxml files for the same & let me know where I am doing wrong in it. I will really appreciate your response. Please reply me ASAP. Its really urgent. Thanks. [file name=Test-f1b9402295be099b552ffbb9f739ad2a.zip size=3533]
  7. szaboaz wrote: In index.jsp lines 35-43 and lines 52-57 are for the usage of datasources in relation of a subreport. I used datasources for both the master (masterreport_ds.jrxml) and the subreport (subreport_ds.jrxml). Subreport's datasource is put into the parameters of the master report, and this very same parameter is set as Data Source Expression in the subreport element of masterreport_ds.jrxml. Lines 59-64 (now commented out) demonstrates the usage of subreports without datasources (using only the Connection object). This time, masterreport_sql.jrxml and subreport_sql.jrxml contain their own sql query string. If you watch the two result pdfs carefully, you can notice one important thing about datasources: result_with_connection.pdf contains three records from master report, and every record has its own subreport section containing several records from the subreport. However, result_with_datasources.pdf contains the three records from the master report also, but only the first record has its own subreport section, the second and third one doesn't. This is because the subreport datasource is consumed first time. If you want to give a datasource to a subreport, you have to be careful, to assure that your subreport will appear only once. Best regards, Arpad [file name=subreport_with_datasource.zip size=16476] Post edited by: szaboaz, at: 2008/07/16 09:30 Post edited by: szaboaz, at: 2008/07/16 09:32 Hello, Thanks a lot for the response. In my case, master report query is against SQL server DB & subreport query is against Oracle DB. So in that case I need to open two DB connections in JSP. SQL server DB connection will go to master report at fill time & Oracle DB connection for subreport need to pass as a parameter to master report at fill time. I have defined one parameter with type of java.sql.Connection in master report for the oracle DB connection for subreport. this very same parameter is set as Data Source Expression in the subreport element of master report. Master report & sub report will have their own queries & there will be a common field with same data type & value from master report which will connect query in the subreport. e.g subreport query will be select * from test where dept_id = $P{MasterReportDept_ID} Please find attached JSP & JRxml files for the same & let me know where I am doing wrong in it. I will really appreciate your response. Please reply me ASAP. Its really urgent. Thanks. [file name=Test-3819e8ab74998b012570d0135bdcbb72.zip size=3533]
  8. szaboaz wrote: Yeah, subreports are your friends, just like lshannon suggested in the other thread. Arpad Hello, Thanks a lot for your response. If possible can you please give an example for passing datasource connection as a parameter to main report?If possible do attach sample jrxml file for the same. I will really appreciate your response. Please reply me ASAP. Its really urgent. Thanks.
  9. lshannon wrote: Using subreports is a good way to query more than one datasource since the datasource expression for the subreport can be a JDBC Connection (which can be passed in as a parameter to the main report at fill time) or a JRDataSource object (which can be created in a separate java class). Hello, Thanks a lot for your response. If possible can you please give an example for passing datasource connection as a parameter to main report?If possible do attach sample jrxml file for the same. I will really appreciate your response. Please reply me ASAP. Its really urgent. Thanks.
  10. szaboaz wrote: This worked for me: Code: <%@ page contentType="text/plain;charset=UTF-8" language="java" errorPage="" %> <%@ page import="java.io.IOException"%> <%@ page import="java.io.InputStream"%> <%@ page import="java.io.PrintWriter"%> <%@ page import="java.io.StringWriter"%> <%@ page import="java.util.HashMap"%> <%@ page import="java.util.Map"%> <%@ page import="javax.servlet.ServletException"%> <%@ page import="javax.servlet.ServletOutputStream"%> <%@ page import="javax.servlet.http.HttpServlet"%> <%@ page import="javax.servlet.http.HttpServletRequest"%> <%@ page import="javax.servlet.http.HttpServletResponse"%> <%@ page import="net.sf.jasperreports.engine.JRExporterParameter"%> <%@ page import="net.sf.jasperreports.engine.JasperFillManager"%> <%@ page import="net.sf.jasperreports.engine.JasperPrint"%> <%@ page import="net.sf.jasperreports.engine.export.JRTextExporter"%> <%@ page import="net.sf.jasperreports.engine.export.JRTextExporterParameter"%> <% try { response.setContentType("text/plain"«»); response.setHeader("Content-Disposition", "inline; filename=xyz.txt"«»); ServletOutputStream servletOutputStream = response.getOutputStream(); InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("/reports/example.jasper"«»); Map parameters = new HashMap(); JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, parameters); JRTextExporter exporter = new JRTextExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRTextExporterParameter.OUTPUT_STREAM, servletOutputStream); exporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, new Integer(10)); exporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, new Integer(10)); exporter.exportReport(); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain"«»); response.getOutputStream().print(stringWriter.toString()); } %> Best regards, Arpad Hi, I come across requiremt in which I need to connect to the multiple data sources in one report. Can you give me example/code on how to pass/connect to multiple datasources in one report? I will really appreciate the response. Please reply me ASAP. It really urgent. Thanks.
  11. Hi All, I come across requiremt in which I need to connect to the multiple data sources in one report. Can some one give me example/code on how to pass/connect to multiple datasources in one report? I will really appreciate the response. Please reply me ASAP. It really urgent. Thanks.
  12. Hi Everyone, How to pull data from web service using jasper reports? As I need to generate report by pulling data from web service. If possible give me some example or steps to do it. I will really appreciate response. Plz help me its very urgent. Thanks. Post edited by: HBK32, at: 2008/07/10 18:24
  13. HBK32

    d

    d Post edited by: HBK32, at: 2008/07/10 13:52
  14. szaboaz wrote: Your server basically gives two kinds of things to your browser: the headers, and the data. You always have to set the headers first, and after that, you can put your data to the output stream. You indeed call response.setContentType("application/vnd.ms-excel"); before you send the data, BUT look what happens: your JSP contains lines like <HTML><BODY>. Your server actually starts to give these (as data) to the browser, so any call of setContentType inside the code block is too late. Since you won't put html tags to the output in this situation, you can use a servlet for this as well. But I was interested, if a jsp has anything wrong to it, so I created a short example, as a servlet first, then I put the code into a jsp. I put both of them here. They are working for me, I hope you will find them useful. Best regards, Arpad First, the servlet: Code: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.example; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.export.JRXlsExporter; import net.sf.jasperreports.engine.export.JRXlsExporterParameter; /** * * @author szaboaz */ public class BrowseExcelServlet extends HttpServlet { /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { response.setContentType("application/vnd.ms-excel"«»); response.setHeader("Content-Disposition", "inline; filename=xyz.xls"«»); ServletOutputStream servletOutputStream = response.getOutputStream(); InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("/reports/example.jasper"«»); Map parameters = new HashMap(); JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, parameters); JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, servletOutputStream); exporter.exportReport(); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain"«»); response.getOutputStream().print(stringWriter.toString()); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP <code>GET</code> method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP <code>POST</code> method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. */ public String getServletInfo() { return "Short description"; }// </editor-fold> } And the jsp: Code:[code] <%@ page contentType="application/vnd.ms-excel;charset=UTF-8" language="java" import="java.sql.*" errorPage="" %> <%@ page import="java.io.IOException"%> <%@ page import="java.io.InputStream"%> <%@ page import="java.io.PrintWriter"%> <%@ page import="java.io.StringWriter"%> <%@ page import="java.util.HashMap"%> <%@ page import="java.util.Map"%> <%@ page import="javax.servlet.ServletException"%> <%@ page import="javax.servlet.ServletOutputStream"%> <%@ page import="javax.servlet.http.HttpServlet"%> <%@ page import="javax.servlet.http.HttpServletRequest"%> <%@ page import="javax.servlet.http.HttpServletResponse"%> <%@ page import="net.sf.jasperreports.engine.JRExporterParameter"%> <%@ page import="net.sf.jasperreports.engine.JasperFillManager"%> <%@ page import="net.sf.jasperreports.engine.JasperPrint"%> <%@ page import="net.sf.jasperreports.engine.export.JRXlsExporter"%> <%@ page import="net.sf.jasperreports.engine.export.JRXlsExporterParameter"%> <% try { response.setContentType("application/vnd.ms-excel"«»); response.setHeader("Content-Disposition", "inline; filename=xyz.xls"«»); ServletOutputStream servletOutputStream = response.getOutputStream(); InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("/reports/example.jasper"«»); Map parameters = new HashMap(); JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, parameters); JRXlsExporter exporter = new JRXlsExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, servletOutputStream); exporter.exportReport(); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain"«»); response.getOutputStream().print(stringWriter.toString()); } %> Post edited by: szaboaz, at: 2008/07/08 19:38<br><br>Post edited by: szaboaz, at: 2008/07/08 19:41 Hello, Thanks a bunch for your reply. Your JSP code works for me for xls & pdf. Simillarly I want to open txt file in browser, in that case what code change is required in jsp(jsp code which you have provided)?? I have changed code as following & its opening in browser but could't maintain the report format. Code:[code] <%@ page contentType="text/plain;charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <jsp:useBean id="db" class="ConnDB.DB" scope="request" > <jsp:«»setProperty name="db" property="*" /> </jsp:useBean> <%@ page import="ConnDB.*"%> <%@ page import="java.io.IOException"%> <%@ page import="java.io.InputStream"%> <%@ page import="java.io.PrintWriter"%> <%@ page import="java.io.StringWriter"%> <%@ page import="java.util.HashMap"%> <%@ page import="java.util.Map"%> <%@ page import="javax.servlet.ServletException"%> <%@ page import="javax.servlet.ServletOutputStream"%> <%@ page import="javax.servlet.http.HttpServlet"%> <%@ page import="javax.servlet.http.HttpServletRequest"%> <%@ page import="javax.servlet.http.HttpServletResponse"%> <%@ page import="java.util.*" %> <%@ page import="java.io.*" %> <%@ page import="java.sql.Connection"%> <%@ page import="net.sf.jasperreports.engine.*" %> <%@ page import="net.sf.jasperreports.engine.util.*" %> <%@ page import="net.sf.jasperreports.engine.export.*" %> <%@ page import="net.sf.jasperreports.engine.JRExporterParameter"%> <%@ page import="net.sf.jasperreports.engine.JasperFillManager"%> <%@ page import="net.sf.jasperreports.engine.JasperPrint"%> <%@ page import="net.sf.jasperreports.engine.export.JRXlsExporter"%> <%@ page import="net.sf.jasperreports.engine.export.JRXlsExporterParameter"%> <% try { String BuildID = (String)session.getAttribute("BuildingID"«»); Map parameters = new HashMap(); parameters.put("InputValue1",BuildID); response.setContentType("text/html"«»); Connection conn=(new DB()).connect("Weblogic","svrabm"«»); ServletOutputStream servletOutputStream = response.getOutputStream(); InputStream reportStream = getServletConfig().getServletContext().getResourceAsStream("/InfactAdhoc.jasper"«»); JasperPrint jasperPrint = JasperFillManager.fillReport(reportStream, parameters, conn); response.setHeader("Content-Disposition", "inline; filename="+jasperPrint.getName().toString()+".txt"«»); //File destFile = new File(reportFile.getParent()+"/TXT", jasperPrint.getName() + ".txt"«»); JRTextExporter exporter = new JRTextExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRTextExporterParameter.OUTPUT_STREAM, servletOutputStream); exporter.setParameter(JRTextExporterParameter.PAGE_WIDTH, new Integer(150)); exporter.setParameter(JRTextExporterParameter.PAGE_HEIGHT, new Integer(100)); exporter.exportReport(); servletOutputStream.flush(); servletOutputStream.close(); } catch (Exception e) { // display stack trace in the browser StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); e.printStackTrace(printWriter); response.setContentType("text/plain"«»); response.getOutputStream().print(stringWriter.toString()); } %> I will really appreciate your response. Thanks.
  15. lshannon wrote: I just took a very fast look at your code. It looks like you are creating the FileOutputStream before you actually export the report. Try moving that line down to after you call exporter.exportReport()? Hope that helps. Hello, Thanks a bunch for yr quick reply.I appreciate it. As per yr suggestion I did(moved FileOutputStream line after exporter.exportReport) it but still it didn't open. If possible for you than can you plz look at my code again tell me what should I do? I will really appreciate yr response. Thanks.
×
×
  • Create New...