聊一聊web应用对象:ServletContext
来源:互联网 发布:万网域名绑定非80端口 编辑:程序博客网 时间:2024/06/05 15:42
**定义:**WEB容器启动时,他会为每个web应用程序都创建一个对应的ServletContext对象,它代表当前web应用
ServletContext对象通常也被称为context**域对象**。
ServletConfig对象中维护了ServletContext对象的引用,可以通过ServletConfig、getServletContext方法获得ServletContext对象。
demo1存入对象 ServletContext demo2中取出来
ServletContext的作用
获取WEB应用的全局初始化参数。
String getInitParameter(String name)
Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist.
Enumeration getInitParameterNames()
Returns the names of the context’s initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters.
实现数据的共享
删除数据
void removeAttribute(String name)
Removes the attribute with the given name from the servlet context.
存入数据
void setAttribute(String name, Object object)
Binds an object to a given attribute name in this servlet context.
获取数据
Object getAttribute(String name)
Returns the servlet container attribute with the given name, or null if there is no attribute by that name.
读取资源文件
InputStream getResourceAsStream(String path)
Returns the resource located at the named path as an InputStream object.
注意 setAttribute(String name,object) 把一个java对象和一个属性名绑定,并存放到ServletContext中,参数name指定属性名,参数Objcet表示共享数据。
小练习: 要求: 点击访问网页的次数,反馈到页面中
- 聊一聊web应用对象:ServletContext
- ServletContext对象的应用
- ServletConfig对象,ServletContext对象应用
- (18)servletContext应用:获取web应用的初始化参数、实现servlet转发、利用servletContext对象读取资源文件
- ServletContext与Web应用范围
- ServletContext与Web应用范围
- ServletContext与Web应用范围
- ServletContext对象方法的应用
- Servlet的细节、ServletConfig对象、ServletContext对象及ServletContext应用
- 在Web 应用的生命周期中,ServletContext 对象最早被创建,最晚被销毁。
- 笔记之servlet的ServletContext对象(ServletContext的应用)
- Tomcat ServletContext 和 web应用的关系
- Web应用共享数据区ServletContext接口
- Web应用共享数据区ServletContext接口
- ServletContext读取web应用中的资源文件
- ServletContext 读取Web应用中的资源文件
- 域对象——ServletContext及应用
- servlet简单应用和ServletContext对象
- 利用xcodeproj修改xcode工程文件
- 我的博客目录
- 2016湘潭邀请赛 XTU 1243 2016
- Android---网络请求
- 新版chrome调整开发者工具位置方式改变
- 聊一聊web应用对象:ServletContext
- 从命令行程序学习Objective-C的类和函数
- Android 7.1 Shortcuts功能
- Winner-take-all Autoencoder
- 代理模式之继承式静态代理
- SourceInsight Macro编程-1
- java中finally的执行顺序
- Fragment中使用工具栏总结
- The KITTI Vision Benchmark Suite之Sensor Setup篇章