JavaWeb的Filter中获取当前项目物理路径

来源:互联网 发布:java中的类 编辑:程序博客网 时间:2024/05/22 17:18

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("/");}



0 0