ServletConfig对象详解
在Servlet 的配置文件中,可以用一个或多个<init-param>标签为servlet配置一些初始化参数。
当servlet配置了初始化参数之后,web容器在创建servlet实例对象时,会自动将这些初始化参数封装到ServletConfig对象中,并在调用servlet的init方法时,将ServletConfig对象传递给Servlet。进而,程序员通过Servlet对象得到当前servlet的初始化参数信息。
获取ServletConfig中初始化信息步骤:
1 . 创建私有变量:
private ServletConfig config = null;
2、重写init方法,令 this.config = config,从而获取ServletConfig对象
3、获取<init-param>中的配置信息
//获取初始化参数
String value1 = this.config.getInitParameter("x1");
//获得配置文档中<inti-param>标签下name对应的value
String value2 = this.config.getInitParameter("x2");
//获取所有初始化参数
Enumeration e = this.config.getInitParameterNames();
while(e.hasMoreElements()){
String name = (String) e.nextElement();
String value = this.config.getInitParameter(name);
System.out.println(name+"="+value);
}
4、开发中ServletConfig的作用有:
获取字符集编码:
String charset = this.config.getInitParameter("charset");
获得数据库连接信息:
String url = this.config.getInitParameter("url");
String username = this.config.getInitParameter("username");
String password = this.config.getInitParameter("password");
获得配置文件:
String configFile = this.config.getInitParameter("config");
ServletConfig对象详解的更多相关文章
- (15)ServletConfig对象详解
1,作用 主要是用于加载servlet的初始化参数.在一个web应用可以存在多个ServletConfig对象(一个Servlet对应一个ServletConfig对象) 2,创建时机和对象的获取 创 ...
- mvc-servlet---ServletConfig与ServletContext对象详解(转载)
ServletConfig与ServletContext对象详解 一.ServletConfig对象 在Servlet的配置文件中,可以使用一个或多个<init-param>标签为s ...
- JavaWeb学习----JSP内置对象详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- Servlet、ServletContext与ServletConfig的详解及区别
Servlet.ServletContext与ServletConfig的详解及区别 一.Servlet详解 Servlet是一个interface,全局限定名:javax.servlet.Servl ...
- jQuery的deferred对象详解
jQuery的deferred对象详解请猛击下面的链接 http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_ ...
- Window 对象详解 转自 http://blog.csdn.net/jcx5083761/article/details/41243697
详解HTML中的window对象和document对象 标签: HTMLwindowdocument 2014-11-18 11:03 5884人阅读 评论(0) 收藏 举报 分类: HTML& ...
- jQuery的deferred对象详解(转载)
本文转载自: jQuery的deferred对象详解(转载)
- JS中的event 对象详解
JS中的event 对象详解 JS的event对象 Event属性和方法:1. type:事件的类型,如onlick中的click:2. srcElement/target:事件源,就是发生事件的 ...
- django中request对象详解(转载)
django中的request对象详解 Request 我们知道当URLconf文件匹配到用户输入的路径后,会调用对应的view函数,并将 HttpRequest对象 作为第一个参数传入该函数. ...
随机推荐
- DOM 事件
1.注册事件 // 事件处理函数 function handleMouseOver(event) { // process ...... } p.addEventListener("mous ...
- python数据挖掘领域工具包
原文:http://qxde01.blog.163.com/blog/static/67335744201368101922991/ Python在科学计算领域,有两个重要的扩展模块:Numpy和Sc ...
- 【Android UI】Android ListView详解
在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示.抽空把对ListView的使用做了整理,并写了个小例子,如下图. 列表的显示需要三 ...
- C#数据结构杂记
定义任何类时记得要定义无参构造函数,否则在反序列化的时候会抛出异常. [Serialize]声明该类可以被序列化 Const与readonly的区别 const本质上是常量没有任何方法修改值,read ...
- hdu 4982 Goffi and Squary Partition
Goffi and Squary Partition Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Subm ...
- JavaScript 基础第七天(DOM的开始)
一.引言 JavaScript的内容分为三个部分,这三个部分分别是ECMAScript.DOM.BOM三个部分组成.所谓ECMAScript就是JavaScript和核心基础语法,DOM是文档对象模型 ...
- iOS一些关于日历的问题
int CalculateDays(int ys, int ms, int ds, int ye, int me, int de) { int days = CalcYearRestDays(ys, ...
- myeclipse导入项目出现乱码
(1)修改整个工作空间的编码方式: Window->Preferences->General->Workspace->Text file Encoding 在 Others 里 ...
- Flask的socket.error:10053
一脸懵逼: 学习python一段时间,最近使用flask搭建了一个服务器,然后使用phantom(相当于浏览器)发送请求发送了几条flask就挂掉了,报错信息如下: 由于个人python经验不是很足, ...
- 一致性hash的理解
参考: http://www.blogjava.net/hello-yun/archive/2012/10/10/389289.html http://blog.csdn.net/cywosp/art ...