2012-10-30 39 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 –