Same chart is being displayed every time-ITS urgent!
Same chart is being displayed every time-ITS urgent!
Hi,
I have used frames with a left frame containing menu and right frame displaying the chart. When I click the links on the menu the chart would be rendered on the right frame. The chart that I get for the first click, this is the same chart that I am getting on the right frame for every other click on the menu. I have see the 'View Source' of the browser, the map info is that of the new chart but the chart that was displayed for the first click is being displayed again and again.
Please help.
Here is the index.jsp:
<frameset cols="210,*" frameborder=0>
<frame src="xpmenu.jsp">
<frame src="welcome.jsp" name="showframe">
</frameset>
Here is the xpmenu.jsp:
<div style="float: left" class="navbar">
<!-- *********************************Start Menu****************************** -->
<div class="mainDiv" >
<div class="topItem" >call status on X axis</div>
<div class="dropMenu" ><!-- -->
<div class="subMenu" style="display:inline;">
<div class="subItem"><a href="<%=request.getContextPath()%>/displaychart.jsp?type=bar" target ="showframe">3-D Bar View</a></div>
</div>
</div>
</div>
<!-- *********************************End Menu****************************** -->
<br>
<!-- *********************************Start Menu****************************** -->
<div class="mainDiv" >
<div class="topItem" >Date of X axis</div>
<div class="dropMenu" ><!-- -->
<div class="subMenu" style="display:inline;">
<div class="subItem"><a href="<%=request.getContextPath()%>/displaychart.jsp?type=stackedline" target ="showframe">Line View</a></div>
<div class="subItem"><a href="<%=request.getContextPath()%>/displaychart.jsp?type=stackedarea" target ="showframe">Stacked Area View</a></div>
</div>
</div>
</div>
<!-- *********************************End Menu****************************** -->
<br>
<div class="mainDiv" >
<div class="topItem" >Calendar</div>
<div class="dropMenu" ><!-- -->
<div class="subMenu" style="display:inline;">
<div id="calendar-container"></div>
</div>
</div>
</div>
<script type="text/javascript" src="xpmenuv21.js"></script>
</div>
Here is the displaychart.jsp:
<body>
<center>
<%
JFreeChart chartobj = null;
String altname = "";
String chartdesc="";
String chartquery="";
String charttype = request.getParameter("type").toString();
BufferedImage bufimage = null;
// get ImageMap
ChartRenderingInfo info = new ChartRenderingInfo();
String imageMap = null;
if(charttype.equals("bar"))
{
chartobj = CreateChartClass.generateBarChart();
altname = "result cnt order by call status cd";
session.setAttribute("title","call status");
session.setAttribute("cname1","Call Status CD");
session.setAttribute("cname2","Result Count");
}
else if(charttype.equals("stackedline"))
{
chartobj = CreateChartClass.generateStackedAreaLineChart("stackedline");
altname = "Test Application on lead_fact";
}
else if(charttype.equals("stackedarea"))
{
chartobj = CreateChartClass.generateStackedAreaLineChart("stackedarea");
}
//populate the info
bufimage = chartobj.createBufferedImage(600, 300, info);
imageMap = ChartUtilities.getImageMap( "map", info );
session.removeAttribute("chartobj");
session.setAttribute( "chartobj", chartobj );
session.removeAttribute("bufimage");
session.setAttribute( "bufimage", bufimage );
%>
<br>
<%= imageMap%>
<IMG src="<%=request.getContextPath()%>/chartviewer" usemap="#map" alt="<%=altname%>" border=1/>
<%=chartdesc%>
<%=chartquery%>
</center>
</body>
</html>
Here is the ChartViewer servelt that streams the chart to the output:
HttpSession session = request.getSession();
// get the chart from storage
JFreeChart chart = (JFreeChart) session.getAttribute( "chartobj" );
// set the content type so the browser can see this as it is
response.setContentType( "image/png" );
// send the picture
BufferedImage buf = chart.createBufferedImage(600, 300, null);
PngEncoder encoder = new PngEncoder( buf, false, 0, 9 );
response.getOutputStream().write( encoder.pngEncode() );
Please help it is very urgent.
Thanks,
Laks.
I have used frames with a left frame containing menu and right frame displaying the chart. When I click the links on the menu the chart would be rendered on the right frame. The chart that I get for the first click, this is the same chart that I am getting on the right frame for every other click on the menu. I have see the 'View Source' of the browser, the map info is that of the new chart but the chart that was displayed for the first click is being displayed again and again.
Please help.
Here is the index.jsp:
<frameset cols="210,*" frameborder=0>
<frame src="xpmenu.jsp">
<frame src="welcome.jsp" name="showframe">
</frameset>
Here is the xpmenu.jsp:
<div style="float: left" class="navbar">
<!-- *********************************Start Menu****************************** -->
<div class="mainDiv" >
<div class="topItem" >call status on X axis</div>
<div class="dropMenu" ><!-- -->
<div class="subMenu" style="display:inline;">
<div class="subItem"><a href="<%=request.getContextPath()%>/displaychart.jsp?type=bar" target ="showframe">3-D Bar View</a></div>
</div>
</div>
</div>
<!-- *********************************End Menu****************************** -->
<br>
<!-- *********************************Start Menu****************************** -->
<div class="mainDiv" >
<div class="topItem" >Date of X axis</div>
<div class="dropMenu" ><!-- -->
<div class="subMenu" style="display:inline;">
<div class="subItem"><a href="<%=request.getContextPath()%>/displaychart.jsp?type=stackedline" target ="showframe">Line View</a></div>
<div class="subItem"><a href="<%=request.getContextPath()%>/displaychart.jsp?type=stackedarea" target ="showframe">Stacked Area View</a></div>
</div>
</div>
</div>
<!-- *********************************End Menu****************************** -->
<br>
<div class="mainDiv" >
<div class="topItem" >Calendar</div>
<div class="dropMenu" ><!-- -->
<div class="subMenu" style="display:inline;">
<div id="calendar-container"></div>
</div>
</div>
</div>
<script type="text/javascript" src="xpmenuv21.js"></script>
</div>
Here is the displaychart.jsp:
<body>
<center>
<%
JFreeChart chartobj = null;
String altname = "";
String chartdesc="";
String chartquery="";
String charttype = request.getParameter("type").toString();
BufferedImage bufimage = null;
// get ImageMap
ChartRenderingInfo info = new ChartRenderingInfo();
String imageMap = null;
if(charttype.equals("bar"))
{
chartobj = CreateChartClass.generateBarChart();
altname = "result cnt order by call status cd";
session.setAttribute("title","call status");
session.setAttribute("cname1","Call Status CD");
session.setAttribute("cname2","Result Count");
}
else if(charttype.equals("stackedline"))
{
chartobj = CreateChartClass.generateStackedAreaLineChart("stackedline");
altname = "Test Application on lead_fact";
}
else if(charttype.equals("stackedarea"))
{
chartobj = CreateChartClass.generateStackedAreaLineChart("stackedarea");
}
//populate the info
bufimage = chartobj.createBufferedImage(600, 300, info);
imageMap = ChartUtilities.getImageMap( "map", info );
session.removeAttribute("chartobj");
session.setAttribute( "chartobj", chartobj );
session.removeAttribute("bufimage");
session.setAttribute( "bufimage", bufimage );
%>
<br>
<%= imageMap%>
<IMG src="<%=request.getContextPath()%>/chartviewer" usemap="#map" alt="<%=altname%>" border=1/>
<%=chartdesc%>
<%=chartquery%>
</center>
</body>
</html>
Here is the ChartViewer servelt that streams the chart to the output:
HttpSession session = request.getSession();
// get the chart from storage
JFreeChart chart = (JFreeChart) session.getAttribute( "chartobj" );
// set the content type so the browser can see this as it is
response.setContentType( "image/png" );
// send the picture
BufferedImage buf = chart.createBufferedImage(600, 300, null);
PngEncoder encoder = new PngEncoder( buf, false, 0, 9 );
response.getOutputStream().write( encoder.pngEncode() );
Please help it is very urgent.
Thanks,
Laks.
It seems the web browser is caching the image, and not reconising that the image is acutally different. Are you using firefox? When I started with dynamic images, firefox would refuse to download the updated image without some pushing.
Anyway, there a few things you can do:
1. Right click on the right frame, push down Ctrl+Shift and click on Reload (ff) or Refresh (ie) - this forces the browser download the new image
2. Tell the web browser to not cache the image via code:
3. Get the jsp to add a parameter to the image url that is unique so that it thinks it is a different image
If doing 1 fixes your problem, implement 2 or 3 (I recommend 2)
Anyway, there a few things you can do:
1. Right click on the right frame, push down Ctrl+Shift and click on Reload (ff) or Refresh (ie) - this forces the browser download the new image
2. Tell the web browser to not cache the image via code:
Code: Select all
JFreeChart chart = (JFreeChart) session.getAttribute( "chartobj" );
// set the content type so the browser can see this as it is
response.setContentType( "image/png" );
// Add this:
response.setHeader("Expires","0");
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
// send the picture
BufferedImage buf = chart.createBufferedImage(600, 300, null);
PngEncoder encoder = new PngEncoder( buf, false, 0, 9 );
response.getOutputStream().write( encoder.pngEncode() );
If doing 1 fixes your problem, implement 2 or 3 (I recommend 2)
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
While suspect the browser cache as well, another possibility is the proxy server cache. If you are running this applet within a corporate intranet, it is possible the proxy is just caching the image. The suggestions of joolz will certainly work for the browser cache, but they may not work on the proxy depending upon the settings. I would suggest you add something to the image just to be sure if joolz suggestions do not work work (they should).joolz wrote:It seems the web browser is caching the image, and not reconising that the image is acutally different. Are you using firefox? When I started with dynamic images, firefox would refuse to download the updated image without some pushing.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
The chart started reloading
Hi,
Yes, you were right that the servlet URL has been same so the browser was rendering the same Chart. I tried the option 3 and it worked. I even tried option 2 but it din't work.
Any idea why the option 2 did not work.
I am using IE6.0 and using a BEA Weblogic Server 8.1
Thanks,
Laks.
Yes, you were right that the servlet URL has been same so the browser was rendering the same Chart. I tried the option 3 and it worked. I even tried option 2 but it din't work.
Any idea why the option 2 did not work.
I am using IE6.0 and using a BEA Weblogic Server 8.1
Thanks,
Laks.
-
- Posts: 844
- Joined: Fri Oct 13, 2006 9:29 pm
- Location: Sunnyvale, CA
Re: The chart started reloading
If option 2 did not work, you probably have a proxy server which is also caching the images. Option 3 tricks the proxy just like it tricks the browser. Irritating behavior for you, but it does allow faster access to common sites.lukkumar wrote:Any idea why the option 2 did not work.
Richard West
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Design Engineer II
Advanced Micro Devices
Sunnyvale, CA
Can you confirm if there is there a proxy server involved?
I'm a bit surprised that #2 doesn't work. I had the same problems, and found that setting those headers did the trick. I am using tomcat6, though that shouldn't make a difference.
I'm not surprised #3 worked, but it will use more disk space in your browser cache, making it a less ideal solution than #2, and is why I mentioned it last.
I'm a bit surprised that #2 doesn't work. I had the same problems, and found that setting those headers did the trick. I am using tomcat6, though that shouldn't make a difference.
I'm not surprised #3 worked, but it will use more disk space in your browser cache, making it a less ideal solution than #2, and is why I mentioned it last.
Re: The chart started reloading
Or should. Not all proxy servers play nice with headers telling them not to cache, I've encountered (though long ago) at least one that cached everything, no-cache headers or no.RichardWest wrote:If option 2 did not work, you probably have a proxy server which is also caching the images. Option 3 tricks the proxy just like it tricks the browser. Irritating behavior for you, but it does allow faster access to common sites.lukkumar wrote:Any idea why the option 2 did not work.
hi joolz and jfree teamsjoolz wrote:It seems the web browser is caching the image, and not reconising that the image is acutally different. Are you using firefox? When I started with dynamic images, firefox would refuse to download the updated image without some pushing.
Anyway, there a few things you can do:
1. Right click on the right frame, push down Ctrl+Shift and click on Reload (ff) or Refresh (ie) - this forces the browser download the new image
2. Tell the web browser to not cache the image via code:3. Get the jsp to add a parameter to the image url that is unique so that it thinks it is a different imageCode: Select all
JFreeChart chart = (JFreeChart) session.getAttribute( "chartobj" ); // set the content type so the browser can see this as it is response.setContentType( "image/png" ); // Add this: response.setHeader("Expires","0"); response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); response.addHeader("Cache-Control", "post-check=0, pre-check=0"); response.setHeader("Pragma", "no-cache"); // send the picture BufferedImage buf = chart.createBufferedImage(600, 300, null); PngEncoder encoder = new PngEncoder( buf, false, 0, 9 ); response.getOutputStream().write( encoder.pngEncode() );
If doing 1 fixes your problem, implement 2 or 3 (I recommend 2)
I am not using response object instead we are using action forward of struts and ajax
so i cannot use 2 method and i dont want to do it manually so i am not preparing to use 1 one also.
but then how to use 3? any example please?
my problem is i created one dash board using charts and graphs which is generated by jfreechart.
after making the data available for the graphs and charts, i saw the dash board still it is showing the old items. but it has created the images its available in the path.
The problem is, its not loaded the latest image
so what i need to do?
Regards
Vaaji
In the code the builds/serves the HTML, construct the URL of the image so that the resulting HTML looks like this:
where 1215556634215 is a uniquely generated number, which could be generated with something like:
Every time you refresh the page, the r parameter will be different, causing the browser to always download the image from the server
Code: Select all
<img src="chart.png?r=1215556634215" />
Code: Select all
System.currentTimeMillis()
thank you joolz,
but i did it another way by adding r with image name.(this solves one more of my problem, thats why i am using this method)
that is every time when i refresh the page it will generate new image
and i point it in the jsp so that the browser caching problem is solved
but i need to delete the old images, that i am trying to do it now any idea?
(ChartDeleter is trying to delete the charts in tmp only - i think so)
but i did it another way by adding r with image name.(this solves one more of my problem, thats why i am using this method)
that is every time when i refresh the page it will generate new image
and i point it in the jsp so that the browser caching problem is solved
but i need to delete the old images, that i am trying to do it now any idea?
(ChartDeleter is trying to delete the charts in tmp only - i think so)