Web.xml配置详解之context-param
来源:互联网 发布:vscode spring boot 编辑:程序博客网 时间:2024/06/05 04:52
• 格式定义:
[html] view plaincopy
- contextConfigLocation
- contextConfigLocationValue>
作用:该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数。
param-name 设定上下文的参数名称。必须是唯一名称
param-value 设定的参数名称的值
•初始化过程:
1.在启动Web项目时,容器(比如Tomcat)会读web.xml配置文件中的两个节点和。
2.接着容器会创建一个ServletContext(上下文),应用范围内即整个WEB项目都能使用这个上下文。
3.接着容器会将读取到转化为键值对,并交给ServletContext。
4.容器创建中的类实例,即创建监听(备注:listener定义的类可以是自定义的类但必须需要继承ServletContextListener)。
5.在监听的类中会有一个contextInitialized(ServletContextEvent event)初始化方法,在这个方法中可以通过event.getServletContext().getInitParameter(“contextConfigLocation”) 来得到context-param 设定的值。在这个类中还必须有一个contextDestroyed(ServletContextEvent event) 销毁方法.用于关闭应用前释放资源,比如说数据库连接的关闭。
6.得到这个context-param的值之后,你就可以做一些操作了.注意,这个时候你的WEB项目还没有完全启动完成.这个动作会比所有的Servlet都要早。
由上面的初始化过程可知容器对于web.xml的加载过程是context-param >> listener >> fileter >> servlet
• 如何使用
1.页面中
${initParam.contextConfigLocation}
2.Servlet中
String paramValue=getServletContext().getInitParameter(“contextConfigLocation”)
声明:此内容为整理所得
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Web.xml配置详解之context-param
- Android开发面试经——1.常见人事面试问题
- 取消京津冀手机漫游费更像文字游戏
- 我为什么选择 iBatis 而不是 Hibernate(对于正在选型的人的建议)
- Android Studio之新建Studio项目
- Hdu 2066 一个人的旅行(dijkstra算法)
- Web.xml配置详解之context-param
- 优化算法的比较,选择
- hive优化
- 【@property的特性】
- Hibernate单向关联1-N
- 【暑期基础2】O HDU 2040 亲和数
- iOS绘图API的使用
- spring配置中mappingResources和mappingLocations
- mysql左连和右连