web.xml<context-param>与<init-param>的作用与区别
web.xml的配置中<context-param>配置作用
1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> 和 <context-param></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>
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")取得.
web.xml<context-param>与<init-param>的作用与区别的更多相关文章
- [转]web.xml中servlet ,filter ,listener ,interceptor的作用与区别
原文链接:https://blog.csdn.net/netdevgirl/article/details/51483273 一.概念: 1.servlet:servlet是一种运行服务器端的java ...
- Spring项目的配置文件们(web.xml context servlet springmvc)
我们的spring项目目前用到的配置文件包括1--web.xml文件,这是java的web项目的配置文件.我理解它是servlet的配置文件,也就是说,与spring无关.即使你开发的是一个纯粹jsp ...
- Struts在Web.xml中的配置及Struts1和Struts2的区别
(1)配置Struts的ActionServlet <servlet>元素来声明ActionServlet <servlet-name>元素:用来定义Servle ...
- web.xml配置详解 (及<context-param>配置作用 )
http://blog.csdn.net/guihaijinfen/article/details/8363839 <context-param>配置作用 http://blog.csdn ...
- Spring与web.xml
出处:http://blog.csdn.net/u010796790 在web.xml配置监听器 ContextLoaderListener (listener-class) ContextLoade ...
- tomcat下的web.xml和项目中的web.xml
Tomcat 服务器中存在一个web.xml文件 在项目文件夹中同样存在一个web.xml文件 那这两个文件有什么区别呢? tomcat中的web.xml是通用的,如果不设置,那么就会默认是同tomc ...
- Tomcat部署web项目,虚拟目录,上下文(Context),WEB-INF,web.xml,servlet,404
Web项目的uri模型大致如下: http://localhost:8080 (/context) (/resource) 站点/上下文/资源 一. Tomcat中指定上下文(Context) 方法一 ...
- springmvc.xml,context.xml和web.xml
1:springmvc.xml配置要点 一般它主要配置Controller的组件扫描器和视图解析器 下为:springmvc.xml文件 <?xml version="1.0" ...
- 使用web.xml方式加载Spring时,获取Spring context的两种方式
使用web.xml方式加载Spring时,获取Spring context的两种方式: 1.servlet方式加载时: [web.xml] <servlet> <servlet-na ...
- 160329(一)、在web.xml文件里配置org.springframework.web.context.ContextLoaderListener
Java代码 <!-- 指明spring配置文件在何处 --> <context-param> <param-name>contextConfigLocation& ...
随机推荐
- 引入外部文件的时候为什么省略http:
[摘要]相信很多时候大家在使用网上的实例代码的时候,需要引入外部文件,然而它们通常都是省略了http:,这是为什么呢? 先给大家看一个简单的小例子,引入外部jquery文件: <script s ...
- Android自定义控件之圆形进度条ImageView
From:http://blog.csdn.net/xiadik/article/details/41648181package com.wangran.beautiful_girl_show.vie ...
- Android之內置、外置SDCard
From:http://blog.csdn.net/u011290399/article/details/10363881 在项目中,发现通过Android提供的API获取外置SDCard的操作一直不 ...
- 160321、ORACLE分页查询SQL语法——最高效的分页
--1:无ORDER BY排序的写法.(效率最高) --(经过测试,此方法成本最低,只嵌套一层,速度最快!即使查询的数据量再大,也几乎不受影响,速度依然!) SELECT * FROM (SELE ...
- Spoken English Practice(I really hate to give her up, oh ,I know, you should take her.)
色:连读: 红色:略读: 蓝色:浊化: 橙色:弱读 下划线_为浊化 口语蜕变(2017/7/10) 英 ...
- 【转】Spring Boot 日志配置(超详细)
更新日志: 20170810 更新通过 application.yml传递参数到 logback 中. [toc] 简书不支持目录,截图一张. image.png 默认日志 Logback: 默认情况 ...
- 排序算法review<1>--直接插入排序
简单插入排序的基本思想:对于原待排序记录中的第i(1<=i<=n-1)个元素Ki,保证其前面的i个元素已经是有序的,要在这前i个元素(K0--Ki-1)中找到合适的位置将第i个元素插入,具 ...
- leadecode 2 Add Two Numbers
package leadcode; /** * 2. Add Two Numbers * Medium * 4067 * 953 * * * You are given two non-empty l ...
- 多进程使用matplotlib.pyplot绘heatmap(多线程不可以)
数据格式如下: 8_15/l_eye/2732.png -20.5773 -5.17769 -3.34583 21.5859 9_13_1/l_eye/1211.png -10.1145 34.992 ...
- docker安装入门
docker安装入门 https://blog.csdn.net/earbao/article/details/49683175