2012-10-30 116 views
0

正如标题所示,即使在映像保存后,我也无法在JSP页面上显示3D饼图。我尝试了绝对路径和相对路径,但它仍然不起作用。有人可以帮助解决这个问题吗?无法在JSP页面上显示3D饼图

这里是源代码:
AnalyzeUserClient.jsp(爪哇码)

DefaultPieDataset pieDataset = new DefaultPieDataset(); 
BufferedReader bReader =new BufferedReader(new FileReader("C:/Users/L31207/Desktop/eclipse-jee-juno-win32/eclipse/user.txt")); 
String s; 
while ((s=bReader.readLine())!=null){ 
    String datavalue [] = s.split("\t"); 
    String category = datavalue[0]; 
    String value = datavalue [1]; 
    pieDataset.setValue(category, Double.parseDouble(value)); 
} 
bReader.close(); 

JFreeChart chart = ChartFactory.createPieChart3D(
      "Percentage of Each Category for User", pieDataset, true, true, true); 

PiePlot3D p = (PiePlot3D) chart.getPlot(); 
p.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}: {2}")); 
p.setForegroundAlpha(0.5f); 
p.setBackgroundAlpha(0.2f); 

chart.setBackgroundPaint(Color.white); 
chart.setAntiAlias(true); 
chart.setBorderVisible(false); 
chart.setTextAntiAlias(true); 

try { 
    ChartUtilities.saveChartAsPNG(new File("C:/Users/L31207/Desktop/eclipse-jee-juno-win32/eclipse/AnalyzeUser.png"), chart, 800, 600); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     System.err.println("Problem occurred creating chart."); 
    } 

AnalyzeUserClient.jsp(HTML代码)

<img src="C:/Users/L31207/Desktop/eclipse-jee-juno-win32/eclipse/AnalyzeUser.png" height="500px" width="500px" usemap="#chart"> 
+0

请参阅此[备选](http://stackoverflow.com/a/13093044/230513)。 – trashgod

回答

1

<img src="..."/>需要引用的资源,所述客户端 - 浏览器不能在与服务器相同的机器上运行 - 可以访问。指向C:驱动器上的文件的href不是这种情况。您需要提供HTTP访问存储在该文件中的映像。

+0

你能给我提供一个代码的例子吗? –

+1

致谢[BalusC](http://stackoverflow.com/users/157882/balusc):http://balusc.blogspot.com/2007/04/imageservlet.html或甚至更好的http://balusc.blogspot。 COM/2009/02/fileservlet支撑用的简历,and.html –