Servlet中init-param与context-param的区别

版权声明:网上学习笔记,共享。 https://blog.csdn.net/qq_37346607/article/details/81217707

<init-parm>配置在<servlet>标签中,用来初始化当前的Servlet的,属于当前Servlet的配置,因此存放在servletConfig对象中;

        通过getServletConfig().getInitParameter("initParam")的方式获取;

<context-param>直接配置在web.xml的<web-app>标签中,属于上下文参数,在整个web应用中都可以使用,它是全局的,因此存放在servletContext对象中(即application对象);

        通过getServletContext().getInitParameter("contextParam")的方式获取;

猜你喜欢

转载自blog.csdn.net/qq_37346607/article/details/81217707