欢迎使用CSDN-markdown编辑器
2016-07-05 15:35
302 查看
web.xml配置记录
servlet
servlet-mapping default通常用于配置由默认servlet访问的文件路径,主要针对静态文件jsp-config
<jsp-config>配置参考: <jsp-config> <taglib> <taglib-uri>Taglib</taglib-uri> <taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location> </taglib> <jsp-property-group> <description>Special property group for JSP Configuration JSP example.</description> <display-name>JSPConfiguration</display-name> <url-pattern>/jsp/* </url-pattern> <el-ignored>true</el-ignored> <page-encoding>GB2312</page-encoding> <scripting-invalid>true</scripting-invalid> <include-prelude>/include/prelude.jspf</include-prelude> <include-coda>/include/coda.jspf</include-coda> </jsp-property-group> </jsp-config>
context-param
作用:该元素用来声明应用范围(整个WEB项目)内的上下文初始化参数。param-name 设定上下文的参数名称。必须是唯一名称
param-value 设定的参数名称的值
初始化过程:
在启动Web项目时,容器(比如Tomcat)会读web.xml配置文件中的两个节点和。接着容器会创建一个ServletContext(上下文),应用范围内即整个WEB项目都能使用这个上下文。
接着容器会将读取到转化为键值对,并交给ServletContext。
容器创建中的类实例,即创建监听(备注:listener定义的类可以是自定义的类但必须需要继承ServletContextListener)。
在监听的类中会有一个contextInitialized(ServletContextEvent event)初始化方法,在这个方法中可以通过event.getServletContext().getInitParameter(“contextConfigLocation”) 来得到context-param 设定的值。在这个类中还必须有一个contextDestroyed(ServletContextEvent event) 销毁方法.用于关闭应用前释放资源,比如说数据库连接的关闭。
得到这个context-param的值之后,你就可以做一些操作了.注意,这个时候你的WEB项目还没有完全启动完成.这个动作会比所有的Servlet都要早。
由上面的初始化过程可知容器对于web.xml的加载过程是context-param >> listener >> fileter >> servlet
如何使用
页面中${initParam.contextConfigLocation}
Servlet中
String paramValue=getServletContext().getInitParameter(“contextConfigLocation”)
相关文章推荐
- 创建KVM虚拟机
- POI Sax 事件驱动解析Excel2007文件
- CSS实现单行、多行文本溢出显示省略号(…)
- iOS后台持续定位并定时上传
- 【HDU】 2136 Largest prime factor
- HTML5中figure标签使用实例
- 2016年7月5日遇到的BUG统计
- mybatis 分页-- 传入page对象
- 线程池----ThreadPoolExecutor机制
- sql内连接,外连接
- SecureCRT 使用技巧
- php js rsa
- CAFFE-源码阅读系列之一
- NGUI 事件 (动画播放完毕调用其他方法)
- USB的NRZI编码
- 让我错过工作机会的网站有哪些
- Mac OSX 下PyCharm 工程中 pyenv 和 virtualenv的使用
- Android实现基于滑动的SQLite数据分页加载技术(附demo源码下载)
- 关于android camera2的开发小记
- Linux shell 常用知识点