How do I deal with temporary image files (like charts)?

If I'm going to produce a Web Page using JSP with images (like charts), then what are the best ways to deal with this?

I mean, if it is just plain HTML it is just streamed to the browser. But with images I have to save them somewhere. But when is it safe to erase them? What is the best way to erase them? I mean what would trigger the erase code? Is there way to run some "sweeper" code once in a while that checks if it is ok to erase these files and, if so, does it?
ycompAsked:
Who is Participating?
 
sompol_kiatkamolchaiConnect With a Mentor Commented:
Yes. it needs temporarily file of generated image. After I review JCharts, I think it's a generic tool for generated image by java.

I recommend you to use cewolf. It's quite easier one. since it's taglib
here is an example

<cewolf:chart     id="XYChart"    type="xy"    title="XYChart">
  <cewolf:gradient>        
      <cewolf:point x="0" y="0" color="#FFFFFF"/>        
      <cewolf:point x="0" y="300" color="#C8C8C8"/>    
  </cewolf:gradient>    
  <cewolf:data>        
    <cewolf:producer id="xyData"/>    
  </cewolf:data>
</cewolf:chart>
<cewolf:img chartid="XYChart" renderer="cewolf" width="400" height="300"/>

more details, http://cewolf.sourceforge.net
0
 
ramazanyichCommented:
If you use some Java packages for image creation (www.jfree.org and cewolf.sourceforge.net) you don't have to store temporary image files.
Image will be generated on the fly by servlet for example and you just need point to servlet (with some parameters) as src attribute value of img element.
Example:
<img src="/cewolf?param=value&param2=value2"/>
0
 
ycompAuthor Commented:
but if my charts are complicated and have many data series, etc. how do I do this easily? I would have to pass a very very long url and write code to parse it all, right?

I'm thinking to use JCharts
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
ycompAuthor Commented:
I mean, I would have to write code to encode all chart parameters to a long url (what is the max length of URLs?) and then decode it all to set the attributes.
0
 
ycompAuthor Commented:
I've been thinking... I guess I can live with this approach provided that I can pass all the data via the URL. Is this feasible? Or is the query string of a URL limited to a certain length?
0
 
sompol_kiatkamolchaiCommented:
You should submit by form and use post method that allow you unlimit length of data.

<form name="form1" method="post" action="servletToGenerateChart">
  <input type="hidden" name="data" value="as long as you want">
</form>
0
 
sompol_kiatkamolchaiCommented:
It depends on web server you use. most of web server do not allow to submit length of url more than 255 byte
0
 
sompol_kiatkamolchaiCommented:
and here is javascript to submit form

<script language="javascript">
  function submitData() {
    document.form1.submit();
  }
</script>

:) just assume you don't know javascript to submit form. If you know, ignore this.
0
 
ycompAuthor Commented:
hi, thanks... I'm a bit confused. How does my form post get turned into an <IMG> tag?
0
 
sompol_kiatkamolchaiCommented:
Are you using cewolf?
0
 
ycompAuthor Commented:
No, I want to use JCharts
0
 
ycompAuthor Commented:
I want to have a JSP file that produces my HTML code. Within that I will have some embedded charts. I want these charts to be based on data that is somehow embedded in the HTML. The HTML should call another JSP to render them.
0
 
ycompAuthor Commented:
That is my new approach to solving my problem (provided it is possible). The 256 char limit in the GET string would be a problem, so I'm trying to find another way.

My old idea was to have the JSP that generates the HTML to also generate the chart images but then they would have to be saved somewhere temporarily (and thus removed eventually somehow, which is a big mess)
0
 
ycompAuthor Commented:
hmm, so it looks likes I'm back to my original question. Thanks for the help though.

Anyone know if there is some generic java library that is made to handle temporary files with a Servlet / JSP image generating environment in mind?
0
 
ycompAuthor Commented:
although my question was not really answered, I learned a lot and have rethought my approach. So I'm closing this topic because I don't think I need to generate temp files anymore.
0
 
ycompAuthor Commented:
sorry I meant "although my INITIAL question was not really answered". thanks for the help.
0
 
sompol_kiatkamolchaiCommented:
thanks :)
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.