方式一:
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
String rootpatch = session.getServletContext().getRealPath("/");
方式二:
public static String getRealPath(String path)
{
return ((ServletContext) FacesContext.getCurrentInstance()
.getExternalContext().getContext()).getRealPath(path);
}
转载于:https://www.cnblogs.com/wubiyu/archive/2008/07/02/1233848.html