fusioncharts下载服务器图片

public ActionForward exportImgOfFunction(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception{
    	String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
    	String absoluPath = path.substring(1,path.lastIndexOf("/WEB-INF"));
    	String filePath = absoluPath+"\\resources\\hostReport\\zhujixingneng.jpg";//图片实际地址,该名称在FCExporter_JPG.jsp中定义
    	try {
    		response.setHeader("Content-Disposition", "attachment; filename="
			        + URLEncoder.encode("主机性能.jpg", "UTF-8"));
			byte[] buffer = new byte[1024];
			FileInputStream fis = new FileInputStream(new File(filePath));
			OutputStream bos = response.getOutputStream();
			int len = 0;
			while ((len = fis.read(buffer)) != -1) {
				bos.write(buffer, 0, len);
			}
			bos.flush();
			bos.close();
			fis.close();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 删除临时文件
		File tempFile = new File(filePath);
		if(tempFile.exists()){
		tempFile.delete();
		}
    	return null;
    }

你可能感兴趣的:(FusionCharts)