ServetContext获取方法
更新:HHH   时间:2023-1-7


一、ServetContext获取方法

  1. 在filter 中获取 (过滤器)


LoginFilter Filter {

    init(FilterConfig filterConfig) ServletException {
        filterConfig.getServletContext()
    }

    doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) IOException, ServletException {
        filterChain.doFilter(servletRequest,servletResponse);
    }

    destroy() {

    }
}



  1. 在servlet中获取

     

     this.getServetContext()

     

  2. 通过ServletRequest获取

    request.getSession().getServletContext()



二.ContextPath 、ServletContextName设置


     ContextPath 是指我们在Idea在部署项目时制定的指定


     ServletContextName在web.xml中设置

      <display-name>haiven-crm</display-name>


返回开发技术教程...