Java and Jasper Report

I have a problem..

i have a jrxml file in which query is present .i take the query and replace this query at runtime by java program  by aatching some paramenter to that qurey
 now i have code which work fine and produce output to pdf shows on broswer
then work on mozilla,IE and opera also


 First time i had query like select * from demo in jrxml   and then i replace the query as select * from demo where username='ashish'

the problem is that after showing the report on the browser i m going to save the pdf by click menu File->Save as then its save the report which have the data of first query mean(Select * from demo)

but when i save from the pdf button which is given in pdf menu tool then its save the result of select * From demo where username ='ashish'   which is perfect (which i want)

so what i  have to do so that when i click on save as option of mozilla broswer it will save the pdf having the queery 2nd which means the report showing on browser

Its Does not happening with IE and opera when i save the pdf from both option (1. from pdf tool save button 2. from file menu--> save as option) its save the pdf which are showing on the broswer PDF(its perfect)

so please help me to solve the problem  i have the code below..





////////////////////////////////////////////////////Code //////////////////////////////////
Connection connection;
ServletOutputStream servletOutputStream =response.getOutputStream();
InputStream reportStream = getServlet().getServletConfig()
.getServletContext().getResourceAsStream("/reports/DbReport.jasper");
response.setContentType("application/pdf");
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/flightstats?user=user&password=secret");
JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream, new HashMap(), connection);
connection.close();
servletOutputStream.flush();
servletOutputStream.close();
return mapping.getInputForward();
Adwait ChitaleyAsked:
Who is Participating?
 
anilallewarCommented:
Hmm..like  I said this seems to be an issue with Mozilla cache..it works differently than IE and opera. Can you check out one thing, after the 2nd page is loaded, clear the cache and try to then do file -> save as.

Here are the instructions to bypass cache

http://en.wikipedia.org/wiki/Bypass_your_cache
0
 
anilallewarCommented:
How are you passing the parameterized query to the Jasper report? I do not see you passing the query as a parameter to the report in the code shown.

It should save the same file as to whatever is in the response.

Can you please provide your jrxml file and info abt parameters so that I can help you further?

0
 
Adwait ChitaleyAuthor Commented:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="RemoteReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30">
      <property name="ireport.zoom" value="1.0"/>
      <property name="ireport.x" value="0"/>
      <property name="ireport.y" value="0"/>
      <queryString>
            <![CDATA[select * from M3_REGIONS
       ]]>
      </queryString>
      <field name="REGION_ID" class="java.lang.Integer"/>
      <field name="REGION_PARENT_ID" class="java.lang.Integer"/>
      <field name="REGION_FULL_NAME" class="java.lang.String"/>
      <field name="REGION_SHORT_NAME" class="java.lang.String"/>
      <field name="REGION_REPORT_NAME" class="java.lang.String"/>
      <pageHeader>
            <band height="25" splitType="Stretch">
                  <staticText>
                        <reportElement x="11" y="0" width="107" height="13"/>
                        <textElement verticalAlignment="Bottom"/>
                        <text><![CDATA[REGION ID]]></text>
                  </staticText>
                  <staticText>
                        <reportElement x="118" y="0" width="110" height="24"/>
                        <textElement/>
                        <text><![CDATA[REGION FULL NAME
      ]]></text>
                  </staticText>
                  <staticText>
                        <reportElement x="236" y="0" width="143" height="24"/>
                        <textElement/>
                        <text><![CDATA[REGION SHORT NAME
      ]]></text>
                  </staticText>
                  <staticText>
                        <reportElement x="399" y="0" width="112" height="24"/>
                        <textElement/>
                        <text><![CDATA[REGION REPORT NAME
      ]]></text>
                  </staticText>
            </band>
      </pageHeader>
      <detail>
            <band height="44" splitType="Stretch">
                  <textField>
                        <reportElement x="11" y="0" width="89" height="24"/>
                        <textElement/>
                        <textFieldExpression class="java.lang.Integer"><![CDATA[$F{REGION_ID}]]></textFieldExpression>
                  </textField>
                  <textField>
                        <reportElement x="118" y="0" width="110" height="24"/>
                        <textElement/>
                        <textFieldExpression class="java.lang.String"><![CDATA[$F{REGION_FULL_NAME}]]></textFieldExpression>
                  </textField>
                  <textField>
                        <reportElement x="399" y="0" width="156" height="24"/>
                        <textElement/>
                        <textFieldExpression class="java.lang.String"><![CDATA[$F{REGION_REPORT_NAME}]]></textFieldExpression>
                  </textField>
                  <textField>
                        <reportElement x="236" y="0" width="143" height="24"/>
                        <textElement>
                              <font fontName="Arial" size="10"/>
                        </textElement>
                        <textFieldExpression class="java.lang.String"><![CDATA[$F{REGION_SHORT_NAME}]]></textFieldExpression>
                  </textField>
            </band>
      </detail>
</jasperReport>


This is my jrxml fiile here is queryString  tag i take read the file and replace by query like
select * from M3_REGIONS
       WHERE REGION_FULL_NAME='Sikkim'
and again whatever the prcessing of jasper i did on the that new file... having the new query

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
anilallewarCommented:
Did you recompile your .jrxml file into a .jasper file before running it again?

A better option would be to send the query as a parameter to the Jasper report from your java code so that the query can be changed on Java side without having to recmpile jasper. For that change the query in jasper to

<parameter name="passedQuery" class="java.lang.String"/>
<queryString>
            <![CDATA[$P{passedQuery}  ]]>
</queryString>

And you can pass the query as below from java code

connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/flightstats?user=user&password=secret");
HashMap params = new hashMap();
params.put("passedQuery", "select * from M3_REGIONS WHERE REGION_FULL_NAME='Sikkim'");
JasperRunManager.runReportToPdfStream(reportStream,servletOutputStream,params , connection);
0
 
Adwait ChitaleyAuthor Commented:
no after that also i get the same problem
when i going to save from menu-->save as then its takes the whole rercord which is not happeing with IE and Opera
0
 
anilallewarCommented:
Can you please elaborate your prob a bit? So with Mozilla when you try to save the file it gives data for the 1st report where as you have data for the 2nd record on the page?

Shouldn't happen thatway; I am assuming that Mozilla is saving the data from the cache. Can you try one thing..open 1st report..clear cache..open 2nd report...save and let us know if that gives you the correct data.
0
 
Adwait ChitaleyAuthor Commented:
anilallewar: Thanks for the response till date.

The issue is not regarding compiling of jasper file or parsing modified query. The JRXML code is compiled and the report is getting displayed in PDF Format in runtime.

We have stored the BASE JRXML code in a database from where the same is taken for compiling. In this BASE JRXML, the SQL String relates to the ENTIRE SET of records from a Database View.

For e.g. ... SELECT * FROM REGIONS

Now, if a user desires to have a list of records starting from the letter S, he selects such preference in the UI and the WHERE CLAUSE of the SQL is appended to the BASE JRXML SQL String...

So the updated JRXML code contains a string:

SELECT * FROM REGIONS WHERE REGION_NAME LIKE 'M%'

It is now that the JRXML is compiled at runtime and the report is displayed in PDF Format.
Since it is a PDF File, it is displayed in the browser using the ADOBE PDF Plugin. WE SEE THE LIST OF REGIONS BEGINNING WITH THE LETTER M IN THE PDF FILE.

The issue begins now...When a user desires to SAVE THIS REPORT.. he has 2 options:

1) Use the SAVE button of Adobe PDF Plugin..
2) Use File->Save As of Browser (Which is beyond our control to enable / disable).

When a user saves the report using the Adobe Plugin, the report is saved normally as desired (List of all regions begenning with letter M)

HOWEVER... WHEN A USER SELECTS THE FILE-> SAVE AS OPTION TO SAVE THE REPORT, THE REPORT GETS SAVED WITH THE ENTIRE RECORDSET.

ALL REGIONS (A TO Z) ARE TAKEN FROM DATABASE AND ARE SAVED IN THE REPORT, INCLUDING THE REGIONS STARTING FROM LETTER M.

The WHERE CLAUSE is ignored in totality. We had provided the JRXML for compilation at runtime which INCLUDED the WHERE CLAUSE.

Such issue faced while saving the report using File --> Save As ... which leads to ignoring of WHERE CLAUSE and selection of the entire recordset occurs in MOZILLA only.

When performed on IE and Opera, desired result of saving a report with letter M was obtained.


I hope I have elucidated the issue to your satisfaction.

Thanks in advance for any probable solution.
0
 
Adwait ChitaleyAuthor Commented:
This is perfect solution .......
Thanks

bt how can i do by using java/Javascript

  <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 1970 00:00:00 GMT">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">


I tried this on jsp page bt its not working
0
 
anilallewarCommented:
Try with

<meta http-equiv="cache-control" content="no-cache, no-store,  must-revalidate">  
<META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 1970 00:00:00 GMT">
<META  HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

Otherwise try setting them as Http headers in your JSP/Code from where you are sending Jasper to stream.

<%
       response.setHeader("Cache-Control", "no-cache, no-store,  must-revalidate");
        response.setHeader("Pragma", "no-cache");
       response.setDateHeader("Expires",0);
%>

0
 
Adwait ChitaleyAuthor Commented:
no its not working
0
 
Adwait ChitaleyAuthor Commented:
when i clear the cache from broswer then i get the proper result but when i do by adding this line in Jsp Code or by adding in Java code then it also gives the cache value
0
 
anilallewarCommented:
Hmm...Mozilla definitely is freaky :) What version are you using?

Do you have firebug enabled in your Mozilla browser? If so, please disable it and check again.

Check out this thread with Mozilla storing the cache in memory. It is supposed to be fixed by Firefox 3/1 onwards :(

https://bugzilla.mozilla.org/show_bug.cgi?id=441751


0
 
Adwait ChitaleyAuthor Commented:
i m working on 3.0.1 version of mozilla
0
 
anilallewarCommented:
Well then that is what might be causing the issue. Can you upgrade to latest version of Mozilla and check out.
0
 
Adwait ChitaleyAuthor Commented:
Nope. Not Working ... any suggestions.?
0
 
anilallewarCommented:
Nope..its a bug with Firefox that you can log on their site. This is the max that I know about; caching is a known issue with Firefox.
0
 
anilallewarCommented:
The question that was asked about why this is happening has been answered correctly by me. All the available options were suggested and were exercised.
The problem now relates to a limitation with Firefox itself that needs to be filed as a bug.
Based on the fact that I provided the root cause for the issue and provided whatever workarounds were feasible, I believe that the points should be assigned to me.
 
0
 
anilallewarCommented:
@thermoduric,

How is this going to be resolved? I have already put in comments supporting why I should be awarded the points; if no other expert has time to review this would my objection be overruled?
0
 
anilallewarCommented:
@thermoduric,

How is this going to be resolved? I have already put in comments supporting why I should be awarded the points; if no other expert has time to review this would my objection be overruled?
0
 
anilallewarCommented:
@Modalot,

I had given the reasons of why points should be awarded to me at the time of raising objection and those comments are already present in the question. There is no point in me again justifying the objection; I assumed that the comment was for other experts to provide pointers.

I am assuming that going forward, I need to also suggest the recommended answers while raising objection.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.