linux上不能显示Jfreechart的图片文件
出现错误:
Jan 23, 2015 4:19:21 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [DisplayChart] in context with path [/aldb] threw exception [Chart image not found] with root cause
javax.servlet.ServletException: Chart image not found
at org.jfree.chart.servlet.DisplayChart.service(DisplayChart.java:149)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
html源代码:
/DisplayChart?filename=jfreechart-5351821214105924657.png
文件存在:
find / -name jfreechart-5351821214105924657.png -print
/home/soft/tomcat7/temp/jfreechart-5351821214105924657.png
ll /home/soft/tomcat7/temp/jfreechart-5351821214105924657.png
-rw-r--r-- 1 root root 21517 Jan 23 16:19 /home/soft/tomcat7/temp/jfreechart-5351821214105924657.png
相关代码:
1 File file = new File(System.getProperty("java.io.tmpdir"), filename); 2 if (!(file.exists())) { 3 throw new ServletException("File ‘" + file.getAbsolutePath() + "‘ does not exist"); 4 } 5 6 boolean isChartInUserList = false; 7 ChartDeleter chartDeleter = (ChartDeleter)session.getAttribute("JFreeChart_Deleter"); 8 9 if (chartDeleter != null) { 10 isChartInUserList = chartDeleter.isChartAvailable(filename); 11 } 12 13 boolean isChartPublic = false; 14 if ((filename.length() >= 6) && 15 (filename.substring(0, 6).equals("public"))) { 16 isChartPublic = true; 17 } 18 19 boolean isOneTimeChart = false; 20 if (filename.startsWith(ServletUtilities.getTempOneTimeFilePrefix())) { 21 isOneTimeChart = true; 22 } 23 24 if ((isChartInUserList) || (isChartPublic) || (isOneTimeChart)) 25 { 26 ServletUtilities.sendTempFile(file, response); 27 if (isOneTimeChart) 28 file.delete(); 29 } 30 else 31 { 32 throw new ServletException("Chart image not found"); 33 }
解决方法:
ServletUtilities.setTempOneTimeFilePrefix("jfreechart"); // 加了这个即可;使得上面代码的第20行结果为true;
String filename = ServletUtilities.saveChartAsPNG(chart, 1024, 400, null, session);
官方解释:
My web application runs fine on my Windows development machine, but when I deploy it to the Unix/Linux production server, it doesn‘t work. What is the problem?
Most likely your server does not have X11 running. This is a Java (AWT/Java2D) issue, not something that is specific to JFreeChart. There is some more information at Sun‘s website:
In addition, the following thread in the JFreeChart forum contains some useful information:
REF:
关于jfreechart的几个知识点
http://wangrusheng5200.iteye.com/blog/406876
http://www.jfree.org/jfreechart/faq.html
http://www.cnblogs.com/dkblog/archive/2007/09/25/1980861.html
http://www.2cto.com/os/201411/354304.html
http://www.linuxidc.com/Linux/2011-04/34633.htm
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。