Saving a PNG file on a server in a Java bean, using JSTL

后端 未结 2 2055
不知归路
不知归路 2020-12-18 16:39

I am writing an update page in JSTL where the user inputs some numbers. I then call a java bean - passing the numbers as parameters - which, using JFreeChart, creates a PNG

相关标签:
2条回答
  • 2020-12-18 17:20

    Write it to the directory path returned from System.getProperty("java.io.tmpdir");

    0 讨论(0)
  • 2020-12-18 17:32

    I would suggest that you use the ServletUtilities class. It saves in the java tempdir AND cleans up when the session is invalidated. :) Another hint for then displaying the file is to use the DisplayChart servlet to get your images. This goes in web.xml

          <servlet>
        <servlet-name>DisplayChart</servlet-name>
        <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
      </servlet>
       <servlet-mapping>
            <servlet-name>DisplayChart</servlet-name>
            <url-pattern>/servlet/DisplayChart</url-pattern>
        </servlet-mapping>
    

    This is then how you display the image using jstl:

    <img src="<c:url value='/servlet/DisplayChart?'><c:param name='filename' value='${yourFileNameHERE}' /></c:url>" alt=""/>
    
    0 讨论(0)
提交回复
热议问题