1.启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> 和 <context-param></context-param>
2.紧接着,容器创建一个ServletContext(上下文),这个WEB项目所有部分都将共享这个上下文.
3.容器将<context-param></context-param>转化为键值对,并交给ServletContext.
4.容器创建<listener></listener>中的类实例,即创建监听.
5.在监听中会有contextInitialized(ServletContextEvent args)初始化方法,在这个方法中获得
ServletContext = ServletContextEvent.getServletContext();
context-param的值 = ServletContext.getInitParameter("context-param的键");
6.得到这个context-param的值之后,你就可以做一些操作了.注意,这个时候你的WEB项目还没有完全启动完成.这个动作会比所有的Servlet都要早.
换句话说,这个时候,你对<context-param>中的键值做的操作,将在你的WEB项目完全启动之前被执行.
7.举例.你可能想在项目启动之前就打开数据库.
那么这里就可以在<context-param>中设置数据库的连接方式,在监听类中初始化数据库的连接.
8.这个监听是自己写的一个类,除了初始化方法,它还有销毁方法.用于关闭应用前释放资源.比如说数据库连接的关闭.
详细解决方案
web.xml的配备中<context-param>配置是起什么作用的
热度:820 发布时间:2012-11-14 10:12:19.0
相关解决方案
- Spring自动扫描 <context:componet-scan>和加了<context:include-filter>以后有什么区别
- Servlet.service() for servlet [jsp] in context with path解决方案
- @Context HttpServletRequest request,@Context HttpServletResponse response,该如何解决
- form1.param.value什么意思?解决思路
- ValueStack 和 Stack Context 有什么区别和联系?该怎么处理
- 怎么将字符串得到控件id 的后续有关问题The name 'dd1' does not exist in the current context
- Context.RewritePath重写Url的一个有关问题
- SQl asp.net C# context.Response.Write(ret);返回,该怎么解决
- 关于if (!Context.User.Identity.IsAuthenticated )用法解决办法
- context.Response.Write和Response.Write有什么区别?该如何处理
- Context.Request.ApplicationPath 什么意思?马上结分解决方法
- SDK里的"context"(上下文)具体指的是什么?解决方案
- 在intellij IDE 中配置完服务器出现“duplicated context path ‘/’”错误
- Name jdbc is not bound in this Context 怎么解决?
- web.xml 中的listener context 标签是否冲突
- [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source
- <jsp:param name="name" value=/>解决方案
- <jsp:param name="name" value=/>该如何解决
- 用@component的bean id, 在spring配置文件app.context.html中的摘引
- (四)事件处理――(10)事件处理上下文(Event handler context)
- DWR惯用<init-param>参数
- 紧急Error configuring application listener of class org.springframework.web.context.ContextLoaderListe
- web.xml之<context-param>
- tomcat起动报错:Error configuring application listener of class org.springframework.web.context.ContextLo
- web.xml里边<context-param>与<init-param>的区别与作用
- was修改下上文根后报Failed to load webapp: Context root /* is already bound.异常
- jsp include page <jsp:param value="val" name="n"/>
- JQuery每天函数:核心 jQuery(expression,[context])
- ${name}是${param.name}的简写仍是${requestScope.name}的简写
- <jsp:include ><jsp:forward> 配合 <jsp:param> 乱码有关问题解决