JSF下,获得项目根路径

String newpath= "/img/system/other.png";
ExternalContext exContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) exContext.getRequest();
File file = new File(request.getRealPath(newpath));

if(file.isFile)
{
...
}

你可能感兴趣的:(JSF)