ServletConfig对象
来源:互联网 发布:比亚乔都市印象150数据 编辑:程序博客网 时间:2024/06/04 19:52
ServletConfig:
封装了Servlet的配置信息,并且可以获取ServletContext对象
获取初始化参数:
getInitParameter(String name)获取指定参数名的初始化参数
getInitParameterNames()获取参数名组成的Enumeration对象
getServletContext()
getServletName()获取sevlet的配置名称
ServletContext接口
Servlet引擎为每个WEB应用程序都创建一个对应的ServletContext对象
ServletContext对象被包含在ServletConfig对象中
可以通过ServletConfig.getServletContext()获得
由于一个WEB应用程序中的所有Servlet都共享一个ServletContext对象,所以ServletContext对象被称为application对象(Web应用程序对象)
功能:
获取WEB应用程序的初始化参数
记录日志
application域范围的属性
访问资源文件
获取虚拟路径所映射的本地路径
WEB应用程序之间的访问
ServletContext的其他方法
<servlet><servlet-name>springDispatcher</servlet-name><servlet-class>com.tz.hello</servlet-class><load-on-startup>2</load-on-startup><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/abc.xml</param-value></init-param>//局部的初始化参数</servlet><servlet-mapping><servlet-name>springDispatcher</servlet-name><url-pattern>/</url-pattern></servlet-mapping>
<context-param>//全局的初始化参数<param-name>contextClass</param-name><param-value>org.springframework.web.context.support.TzXmlWebApplicationContext</param-value></context-param>获取当前WEB应用的某一个文件在服务器上的绝对路径,而不是部署前的路径
getRealPath(String path);
获取当前WEB应用的名称:
getContextPath();
获取当前WEB应用的某一个文件对应的输入流:
getResourceAsStream(String path);path的/为相对于当前WEB应用的根目录
以下两种都能获得
ClassLoader classLoader = getClass().getClassLoader();InputStream is = classLoader.getResourceAsStream("abc.properties");HelloServlet hs = new HelloServlet();InputStream is2 = hs.getServletConfig().getServletContext().getResourceAsStream("/WEB-INF/abc.properties");与Attribute相关的后续补上
0 0
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- servletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- ServletConfig对象
- 阿里云linux环境下搭建配置SVN
- 通过configSource提高web.config配置灵活性
- 支持wmv、mpg、mov、avi格式的网页视频播放代码
- JQuery学习笔记(3)
- Android动态设置view的大小及其位置
- ServletConfig对象
- Android systemUI移植
- Android6.0 旋转屏幕(四)应用强制设置方向
- 关于开关电源PCB设计中存在的问题
- P2P系统中的DHT算法分析
- 八个Docker的真实应用场景
- spring IOC
- wifi的两种工作模式
- iOS关于地图定位基础(一)