Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么我们要使用该setAttribute()方法设置 ServletContext 参数,因为我们可以通过设置参数web.xml并使用 获取它们来完成同样的事情getInitParameter()?
setAttribute()
web.xml
getInitParameter()
它servletContext.setAttribute()是动态的,可以在运行时设置和重置。
servletContext.setAttribute()
其中init-parameter指定的web.xml是静态的,在应用程序的生命周期内不会改变。
init-parameter
例子:
init-param