ServletContext基础(还在更新中)
2016-04-08 13:08
369 查看
Web 容器在启动时会加载每一个web 应用程序。
1. ServletContext (Servlet 上下文对象):每个web工程都有自己的ServletContext对象。
范围:应用程序范围。可以被Web 应用程序的所有jsp页面和Servlet 访问。
2. ServletConfig(Servlet 配置对象):每个Servlet 都有自己的ServletConfig对象。
范围:Servlet 范围。
3.
ServletContext 对象是在WEB 应用程序装载时初始化的。
得到ServletContext对象的方法:
1. ServletContext context = getServletContext();
2. ServletContext context = getServletConfig().getServletContext();
得到ServletContext 对象参数的方法:
1. public String getInitParameter(String name); name 为指定的参数值,若不存在,返回null。
2. public Enumeration getInitParameterNames(); 返回所有的参数。
得到ServletContext对象参数值得方法:
ServletContext context = getServletContext();
String value = context.getInitParameter(“name”);
通过ServletContext对象获得资源的方法:
1. public URL getResource(String path);必须以‘/’开头,它相对于Web应用程序的根目录。
2. Public InputStream getResourceAsStream(String path);相当于getResource(path).openStream()。
3. public String getRealPath(String path);返回给定路径的绝对路径。
1. ServletContext (Servlet 上下文对象):每个web工程都有自己的ServletContext对象。
范围:应用程序范围。可以被Web 应用程序的所有jsp页面和Servlet 访问。
2. ServletConfig(Servlet 配置对象):每个Servlet 都有自己的ServletConfig对象。
范围:Servlet 范围。
3.
ServletContext 对象是在WEB 应用程序装载时初始化的。
得到ServletContext对象的方法:
1. ServletContext context = getServletContext();
2. ServletContext context = getServletConfig().getServletContext();
得到ServletContext 对象参数的方法:
1. public String getInitParameter(String name); name 为指定的参数值,若不存在,返回null。
2. public Enumeration getInitParameterNames(); 返回所有的参数。
得到ServletContext对象参数值得方法:
ServletContext context = getServletContext();
String value = context.getInitParameter(“name”);
通过ServletContext对象获得资源的方法:
1. public URL getResource(String path);必须以‘/’开头,它相对于Web应用程序的根目录。
2. Public InputStream getResourceAsStream(String path);相当于getResource(path).openStream()。
3. public String getRealPath(String path);返回给定路径的绝对路径。
相关文章推荐
- 汉堡博客
- 关于Android避免按钮重复点击事件
- Activity区分平板和手机加载布局文件
- 队列
- Lambda 表达式的示例-来源(MSDN)
- WebSphere安装、系统部署、连接池
- Nginx/tengine里的那些timeout时间
- 常用SQL查询语句
- zabbix监控nginx连接状态(转)
- Hdoj-1563-Find your present!
- kafka创建topic报错:KeeperException$NoNodeException: KeeperErrorCode = NoNode for /brokers/ids
- java导出Excel通用方法
- Android数据库 SQLite数据库
- Median of Two Sorted Arrays
- HDU 3629-Convex找凸四边形个数(扫描+二分/two pointers)
- 常见jquery函数集合总结
- 唯品会——java开发实习生机试
- 几种最常见的网站盈利模式分析
- Delphi 实现Ini文件参数与TEdit和TCheckBox绑定(TSimpleParam)
- android数据存储——文件存储