传值: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包如下 ...
随机推荐
- LES on MCT
- c# 缓存!
做项目的时候获取所有城市的时候,发现每次去获取都花费了很多时间,所以用缓存方法让效率更高! 这是我做的例子,如下: public class CacheGetCity { /// <summar ...
- project处理 InteropServices.COMException 异常
project文件无法上传,在上传中的hangfire出现了这个异常 System.Runtime.InteropServices.COMException 这个是因为website的权限是IUser ...
- MYSQL中的主要查询方法
#简单查询 #查询表中的所有数据SELECT * FROM test; #查询表中的指定列的数据SELECT cid,cname FROM test; #过滤重复的数据SELECT DISTINCT ...
- mysql模糊查询语句
select * from tbl_actor where first_char like 'p%' order by first_char;
- CentOS和Window互相远程桌面方法
1)VNC服务器配置 (CentOS 5.x安装GNOME桌面环境) # yum groupinstall "GNOME Desktop Environment(CentOS 6.x安装G ...
- [Vue-rx] Handle Image Loading Errors in Vue.js with RxJS and domStreams
When an image fails to load, it triggers an error event. You can capture the error event and merge i ...
- Unity3d代码从Android/IOS迁移到WindowsPhone经验笔记
[1搭建坏境] 推荐:Windows 8.1 Enterprise + Visual studio 2013(完整安装) PS: 假设要Visual Studio 2012,先安装VS再安装WP8/W ...
- Eclipse导入外部项目问题总结
此次在项目开发过程中导入从oksvn下载的共享项目时出现几个项目在不同的IDE导入导出时的问题,为免忘记做例如以下笔记: 1 类路径问题 在Java开发中大多数的开发人员使用的IDE是MyEcl ...
- 关于ZEDboard
核心芯片:核心ZYNQ XC7Z020CLG484 双核Cortex-A9 MPcore.主频达到667MHz,板载512MB内存 12V@3A的电源适配器 使用的SD卡中预装了Linaro系统,这是 ...