How can i store image in my project hosted in open

2019-08-09 08:09发布

i am trying to create chart and save chart in image folder. it works fine locally but when i hosted it in openshift online it doesn't work.

String root = getServletContext().getRealPath("/");
   File savedFile = new File(root+"\\images\\piechart.jpg");
   ChartUtilities.saveChartAsJPEG(savedFile, piechart, 700, 400); 

root gives null so saving is not working ... please help to store image.

1条回答
狗以群分
2楼-- · 2019-08-09 08:27

Instead of saving the chart as an image in a local folder, you can use one of the variations of ChartUtilities.writeChartAs… to write the image to the servlet's OutputStream.

ChartUtilities.writeChartAsJPEG(response.getOutputStream(), …);
ChartUtilities.writeChartAsPNG(response.getOutputStream(), …);
查看更多
登录 后发表回答