1.在init方法中获取
public void init(FilterConfig arg0) throws ServletException { arg0.getServletContext().getRealPath("/"); }
2.在doFilter方法中获取
public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain){ ((HttpServletRequest) request).getSession().getServletContext().getRealPath("/"); }