<context-param>与<init-param>的差别与作用
web.xml的配置中<context-param>配置作用
1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> 和 <context-param></context-param>
context-param的值 = ServletContext.getInitParameter("context-param的键");
换句话说,这个时候,你对<context-param>中的键值做的操作,将在你的WEB项目全然启动之前被运行.
那么这里就能够在<context-param>中设置数据库的连接方式,在监听类中初始化数据库的连接.
<!-- 载入spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml,/WEB-
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<param-name>urlrewrite</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>cluster</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>servletmapping</param-name>
<param-value>*.bbscs</param-value>
</context-param>
<context-param>
<param-name>poststoragemode</param-name>
<param-value>1</param-value>
</context-param>
<listener>
<listener-class>com.laoer.bbscs.web.servlet.SysListener</listener-class>
</listener>
}
String rootpath = sce.getServletContext().getRealPath("/");
System.out.println("-------------rootPath:"+rootpath);
rootpath = rootpath.replaceAll("\\\\", "/");
} else {
rootpath = "/";
}
if (!rootpath.endsWith("/")) {
rootpath = rootpath + "/";
}
Constant.ROOTPATH = rootpath;
logger.info("Application Run Path:" + rootpath);
String urlrewrtie = sce.getServletContext().getInitParameter("urlrewrite");
boolean burlrewrtie = false;
if (urlrewrtie != null) {
burlrewrtie = Boolean.parseBoolean(urlrewrtie);
}
Constant.USE_URL_REWRITE = burlrewrtie;
logger.info("Use Urlrewrite:" + burlrewrtie);
其他略之....
/*终于输出
-------------rootPath:D:\tomcat_bbs\webapps\BBSCS_8_0_3\
2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
2009-06-09 21:51:46,573 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
*/
web.xml里面能够定义两种參数:
(1)application范围内的參数,存放在servletcontext中,在web.xml中配置例如以下:
<context-param>
<param-name>context/param</param-name>
<param-value>avalible during application</param-value>
</context-param>
<servlet>
<servlet-name>MainServlet</servlet-name>
<servlet-class>com.wes.controller.MainServlet</servlet-class>
<init-param>
<param-name>param1</param-name>
<param-value>avalible in servlet init()</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
package com.wes.controller;
import javax.servlet.http.HttpServlet;
super();
}
public void init() throws ServletException ...{
System.out.println("以下的两个參数param1是在servlet中存放的");
System.out.println(this.getInitParameter("param1"));
System.out.println("以下的參数是存放在servletcontext中的");
System.out.println(getServletContext().getInitParameter("context/param"));
}
}
另外一种參数仅仅能在servlet的init()方法中通过this.getInitParameter("param1")取得.
<context-param>与<init-param>的差别与作用的更多相关文章
- Android 标签控件
版本号:1.0 日期:2014.7.24 版权:© 2014 kince 转载注明出处 在有的应用中可能须要设置一些标签来方便用去去查询某些信息,比方手机助手或者购物软件之类都会有一些标签. ...
- android用canvas绘制两种波纹效果
波形效果有几种不同的呈现形式,比如从中间向四周散开的波形,也就是熟知的水涟漪:还有上下波动的曲线,像五线谱等.英文中可以称作Wave或者Ripple,所以暂且叫它们WaveView.WaveLayo ...
- SpringMVC(十六):如何使用编程方式替代/WEB-INF/web.xml中的配置信息
在构建springmvc+mybatis项目时,更常用的方式是采用web.xml来配置,而且一般情况下会在web.xml中使用ContextLoaderListener加载applicationCon ...
- FFmpeg源代码简单分析:日志输出系统(av_log()等)
===================================================== FFmpeg的库函数源代码分析文章列表: [架构图] FFmpeg源代码结构图 - 解码 F ...
- 使用Unity解耦你的系统—PART3——依赖注入
继续学习Unity,在前几篇中已经将Unity的使用方法做了一个还算详细的介绍了,主要是如何通过代码及配置文件来注册对象之间的关系.Unity内置所有的生命周期管理使用介绍,及Unity的Regist ...
- ROS理解参数服务器param demo
param 是一个字典,存储一些变量 param_demo.cpp #include<ros/ros.h> int main(int argc, char **argv){ ros::in ...
- 【记录】@Configuration注解作用 mybatis @Param作用
参考地址: 1:https://www.cnblogs.com/duanxz/p/7493276.html 2:https://www.wandouip.com/t5i91156/ 3:https:/ ...
- salesforce 零基础学习(五十九)apex:param使用以及相关的疑惑
做web项目难免要从一个页面传参数,解析参数中的值进行相关处理以后跳转到其他页面,VF中也不例外.使用传参的标签为apex:param. apex:param标签不可以单独使用,需要作为子标签嵌套在相 ...
- jQuery的ajax 方法提交多个对象数组问题 C# traditional $.param
当用$.ajax()向后台提交参数时,如果参数中数组的话一般在后台会用List<T>接收;但老是不成功如下面代码 "}]; "}]; function addUser( ...
- struts2文件下载及 <param name="inputName">inputStream</param>的理解
转自:http://blog.csdn.net/wnczwl369/article/details/7483290 转自:http://hi.baidu.com/c2_sun/item/934a542 ...
随机推荐
- pair + map 函数结合使用
题目链接:codeforces 44A5birch yellowmaple redbirch yellowmaple yellowmaple green 4 3oak yellowoak yellow ...
- struts-tiles学习笔记
网上搜了一些,稀里糊涂的,要么是代码不全,要么是版本不对,还是去struts官网大概学习了一下 http://struts.apache.org/development/1.x/struts-tile ...
- php 知乎爬虫
http://blog.jobbole.com/88788/ https://github.com/owner888/phpspider 费了半天劲安装了redis,导出cookie,发现仍是缺失很多 ...
- 第一百五十节,封装库--JavaScript,表单验证--密码验证
封装库--JavaScript,表单验证--密码验证 效果图 html <div id="reg"> <h2 class="tuo">& ...
- source insight Confirm by typing ‘yes' below"、"has been changed outside of the editor. Do you want to reload the file?"、“
阅读内核代码习惯和喜欢使用source insight.如果能在source insight上修改内核代码,同时又不需要把修改的内核代码再拷贝到虚拟ubuntu上去那就方便了.于是想通过用samba与 ...
- (随用随总结)Linux下面的特殊权限&不同的文件类型
一.Linux的文件信息 linux文件被保存在文件系统下,由以下属性组成: ls -l 之后看到的信息 从左到右可以看到文件的以下属性 各种类型 访问权限 链接数(跟 inode相关,ln 硬链 ...
- 蓝桥杯 第三届C/C++预赛真题(3) 比酒量(数学题)
有一群海盗(不多于20人),在船上比拼酒量.过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了.再打开一瓶酒平分,又有倒下的,再次重复...... 直到开了第4瓶酒,坐着的已经所剩无几,海盗船 ...
- TArray数组
TArray<int32> arr; arr.Init(,); ; index < arr.Num(); index++) { FString str = FString(" ...
- 广义高斯分布(GGD)
广义高斯分布(GGD)-Generalized Gaussian Distribution 广义高斯分布及其在图像去噪的应用_百度文库 https://wenku.baidu.com/view/2b8 ...
- Django项目实战 - 搜索功能(转)
首先,前端已实现搜索功能页面, 我们直接写后台逻辑: Q()可以实现 逻辑或的判断, name_ _ icontains 表示 name字段包含搜索的内容,i表示忽略大小写. from djang ...