传值:web.xml传递参数 即在Servlet中获取web.xml里的值
传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param
<servlet>
...
<init-param>
<param-name>name</param-name>
<param-value>关羽</param-value>
</init-param>
<init-param>
<param-name>age</param-name>
<param-value>20</param-value>
</init-param>
<init-param>
<param-name>sex</param-name>
<param-value>男</param-value>
</init-param>
</servlet> 在servlet的init()方法中:
String name=this.getServletConfig().getInitParameter("name");
String age=this.getServletConfig().getInitParameter("age"); ServletConfig sc=this.getServletConfig();
//枚举 获取所有配置参数信息
Enumeration e=sc.getServletConfig().getInitParameterNames();
while(e.hasMoreElements()){
syso(sc.getInitParameter(e.nextElement().toString()));
} -----------------------------------
在web.xml中的web-app下配置多个context-param
<context-param>
<param-name></param-name>
<param-value></param-value>
</context-param> <context-param>
<param-name></param-name>
<param-value></param-value>
</context-param> context:一般指上下文环境 ServletContext:指的是整个web项目的上下文环境 ,表示的就是整个web.xml this.getServletContext().getInitParameter("age");
//可以通过局部获得整体(由子到父)
this.getServletConfig().getServletContext().getInitParameter("age"); ServletConfig,ServletContext 可以直接从this(Servlet)中获得这两个对象
ServletConfig scf=this.getServletConfig();
ServletContext sct=this.getServletContext(); init(),init(ServletConfig config):在GenericServlet中,init(ServletConfig config) 里面调用init(),所以覆盖的是init(),而不是init(ServletConfig config)
传值:web.xml传递参数 即在Servlet中获取web.xml里的值的更多相关文章
- Servlet规范简介——web框架是如何注入到Servlet中的
Servlet规范简介--web框架是如何注入到Servlet中的 引言 Web框架一般是通过一个Servlet提供统一的请求入口,将指定的资源映射到这个servlet,在这个servlet中进行框架 ...
- 传递参数:java代码中形参的改变有没有影响实参?
实参:可以是常量.变量.表达式.函数等, 无论实参是何种类型的量,在进行函数调用时,它们都必须具有确定的值, 以便把这些值传送给形参. 因此应预先用赋值,输入等办法使实参获得确定值. 形参:全称为“形 ...
- Web版需求征集系统所得1,servlet中获取checkbox复选框的值
servlet中获取checkbox复选框的值 </tr> <tr> <td align="right">研究类型</td> < ...
- 在Servlet中获取Spring注解的bean
最近由于项目中出现了Servlet调用Spring的bean,由于整个项目中所有的bean均是注解方式完成,如@Service,@Repository,@Resource等,但是Spring的容器管理 ...
- jsp内置对象pageContext如何在Servlet中获取值
pageContext javax.servlet.jsp.PageContext 的实例,该对象代表该JSP 页面上下文,使用该对象可以访问页面中的共享数据.常用的方法有getServletCont ...
- web.xml中在Servlet中获取context-param和init-param内的参数
引自:http://blog.csdn.net/yakson/article/details/9203231 web.xml里面可以定义两种参数:1.application范围内的参数,存放在serv ...
- struts2 在 Action 或 Interceptor 中获取 web.xml 中配置的 <context-param> 参数 (这是我的第一篇博文,哈哈。)
最近为了改一个问题,想加一个控制开关,就在web.xml 中配置了一个 <context-param> 参数,并在 Action 或 Interceptor 中获取参数值. 1.在 web ...
- servlet中获取配置文件中的参数.
web.xml (添加init-param) <?xml version="1.0" encoding="UTF-8"?> <web-app ...
- 01_MyBatis EHCache集成及所需jar包,ehcache.xml配置文件参数配置及mapper中的参数配置
1 与mybatis集成时需要的jar ehcache-core-2.6.5.jar mybatis-ehcache-1.0.2.jar Mybatis.日志.EHCache所需要的jar包如下 ...
随机推荐
- 第九节:web爬虫之urllib(五)
第四个模块 robotparser: 主要是用来识别网站的 robots.txt 文件,然后判断哪些网站可以爬,哪些网站不可以爬的,其实用的比较少.
- BZOJ 4094 USACO 2013 Dec. Optimal Milking
线段树 每个节点保存4个值,both表示左右端点都取,neither表示左右端点都不取,left表示只取左端点,right表示只取右端点. 维护的特殊姿势: $cur$的$both=max(ls.l+ ...
- C. Day at the Beach
codeforces 599c C. Day at the Beach One day Squidward, Spongebob and Patrick decided to go to the be ...
- PAT 1129 Recommendation System
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
- [spoj1182][Sorted Bit Sequence] (数位dp)
Description Let's consider the 32 bit representation of all integers i from m up to n inclusive (m ≤ ...
- JavaScript 面向对象的编程(二) 类的封装
类的定义 方式一 var Book = function(id, name, price){ //私有属性,外部不能直接访问 var num = 1; //私有方法, function checkId ...
- 【Codeforces 339C】Xenia and Weights
[链接] 我是链接,点我呀:) [题意] 在天平上放砝码 你要在左边放一下然后到右边放一下 一直重复这样放m次 每次你放在其中一边都要让另外一边的重量比你少 你可以用1~10中的某些砝码 问你要怎样放 ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第12章节--SP 2013中远程Event Receivers
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第12章节--SP 2013中远程Event Receivers 本章中,你讲学到: 了解远程evernt ...
- Python3基础(十) 类的初印象
Python是一种面向对象的脚本语言,所以它也提供了面向对象编程的所有基本特征:允许多继承的类继承机制.派生类可以重写它父类的任何方法.一个方法可以调用父类中同名的方法.对象可以包含任意数量和类型的数 ...
- Cocos Code IDE + Lua初次使用FastTiledMap的坑
近期想玩玩Lua.又想玩玩Cocos Code IDE.更加想写一个即时战斗的.防守的.会动的.有迷雾的.要探索的(旁白:给我停!)跑地图游戏. 于是我就用Cocos Code IDE来写游戏了.挑战 ...