/**
* 在JAVA后台取文件路径
*/
//取根的绝对路径
URL basePath = Thread.currentThread().getContextClassLoader().getResource("");
//取相对路径
String realPath = new File(basePath.getFile(),"../../" + url).getCanonicalPath();
//转换空格
realPath = URLDecoder.decode(realPath,"utf-8");
//打开文件
InputStream is = new FileInputStream(realPath);
/**
* 在Servlet中取路径
*/
ServletContext application = this.getServletConfig().getServletContext();
String filePath = context.getResource(url).toString();
InputStream is = new java.net.URL(filePath).openStream();
/**
* 在JSF中取路径
*/
HttpServletResponse response =(HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
InputStream inputStream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(path);
ServletOutputStream servletOutputStream = response.getOutputStream();