getServletConfig() 与getServletContext() 的区别
2011-11-07 20:09
330 查看
getServletConfig() 在servlet初始化时,容器传递进来一个ServletConfig对象并保存在servlet实例中,该对象允许访问两项内容:初始化参数和 ServletContext对象,前者通常由容器在文件中指定, 允许在运行时向sevrlet传递有关调度信息,比如说getServletConfig().getInitParameter("debug")后者为servlet提供有关容器的信息。 此方法可以让servlet在任何时候获得该对象及配置信息。 getServletContext()
一个servlet可以使用getServletContext()方法得到web应用的servletContext 即而使用getServletContext的一些方法来获得一些值 比如说getServletContext().getRealPath("/")来获得系统绝对路径 getServletContext().getResource("WEB-INF/config.xml")来获得xml文件的内容 getServletContext()取得的是 配置的参数 getServletConfig()取得的是
配置的参数 2: getServletContext()应用于整个web App,而getServletConfig()仅应用于当前Servlet。 但是ServletConfig对象拥有ServletContext的引用。所以可以通过getServletConfig()来获得web App的 初始值。
一个servlet可以使用getServletContext()方法得到web应用的servletContext 即而使用getServletContext的一些方法来获得一些值 比如说getServletContext().getRealPath("/")来获得系统绝对路径 getServletContext().getResource("WEB-INF/config.xml")来获得xml文件的内容 getServletContext()取得的是 配置的参数 getServletConfig()取得的是
配置的参数 2: getServletContext()应用于整个web App,而getServletConfig()仅应用于当前Servlet。 但是ServletConfig对象拥有ServletContext的引用。所以可以通过getServletConfig()来获得web App的 初始值。
相关文章推荐
- getServletContext和getServletConfig中getInitParameter的区别
- getServletConfig() 与getServletContext() 的区别
- getServletContext和getServletConfig中getInitParameter的区别
- getServletContext和getServletConfig的getInitParameter方法区别
- getServletConfig() 与getServletContext() 的区别 .
- getServletContext()以及getServletConfig() 与getServletContext() 的区别
- getServletConfig() 与getServletContext() 的区别
- getServletContext和getServletConfig都有getInitParameter的方法 区别
- getServletConfig() 与getServletContext() 的区别
- Servlet、ServletContext与ServletConfig的详解及区别
- Servlet、ServletContext与ServletConfig的详解及区别
- ServletContext和ServletConfig的区别
- 学习笔记--【转】Parameter与Attribute的区别&servletContext与ServletConfig区别
- getServletContext()和getServletConfig()
- 在servlet的init方法中使用getServletConfig、getServletContext时发生nullpointerexception
- Java--Servlet、ServletContext与ServletConfig的详解及区别
- ServletConfig和ServletContext的区别
- ServletConfig与ServletContext的区别与联系
- ServletRequest中的getAttribute()和getParameter()以及ServletConfig中的getInitParameter()方法的区别
- ServletConfig与ServletContext的区别