博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
传值:web.xml传递参数 即在Servlet中获取web.xml里的值
阅读量:2205 次
发布时间:2019-05-04

本文共 1493 字,大约阅读时间需要 4 分钟。

1 传值:web.xml传递参数 2  3 在web.xml中的Servlet里配置多个init-param 4 
5 ... 6
7
name
8
关羽
9
10
11
age
12
20
13
14
15
sex
16
17
18
19 20 在servlet的init()方法中:21 String name=this.getServletConfig().getInitParameter("name");22 String age=this.getServletConfig().getInitParameter("age");23 24 25 ServletConfig sc=this.getServletConfig(); //枚举 获取所有配置参数信息26 Enumeration e=sc.getServletConfig().getInitParameterNames();27 while(e.hasMoreElements()){28 syso(sc.getInitParameter(e.nextElement().toString()));29 }30 31 32 -----------------------------------33 在web.xml中的web-app下配置多个context-param34
35
36
37
38 39
40
41
42
43 44 45 context:一般指上下文环境46 47 ServletContext:指的是整个web项目的上下文环境 ,表示的就是整个web.xml48 49 this.getServletContext().getInitParameter("age");50 //可以通过局部获得整体(由子到父)51 this.getServletConfig().getServletContext().getInitParameter("age");52 53 ServletConfig,ServletContext 可以直接从this(Servlet)中获得这两个对象 54 ServletConfig scf=this.getServletConfig();55 ServletContext sct=this.getServletContext();56 57 init(),init(ServletConfig config):在GenericServlet中,init(ServletConfig config) 里面调用init(),所以覆盖的是init(),而不是init(ServletConfig config)

 

转载于:https://www.cnblogs.com/1020182600HENG/p/6088263.html

你可能感兴趣的文章
springboot+jta+atomikos多数据源和 springboot+mybatisplus+aop实现数据库读写分离而引发的一些思考
查看>>
java面试中常考的一些面试sql语句
查看>>
一个字节等于多少位?
查看>>
帧框架frameset的用法总结
查看>>
java1.8中创建hashmap的初始化大小设置标准
查看>>
mark一下,service的实现层没有加@service注解。
查看>>
jq对象转换成js对象。已经jq的复合选择器。
查看>>
(一)alin‘s mysql学习笔记----概述
查看>>
(二)alin’s mysql学习笔记----mysql的存储引擎
查看>>
(三)alin’s mysql学习笔记----常用的join连接查询
查看>>
(四)alin’s mysql学习笔记----索引简介
查看>>
分布式系统中的幂等性的理解
查看>>
spring的注解开发中的常用注解(一)------@bean @Configuration @ComponentScan @Import @Scope @Lazy
查看>>
(五)alin’s mysql学习笔记----索引性能分析
查看>>
Spring中使用@Transactional注解进行事务管理的时候只有应用到 public 方法才有效
查看>>
springboot整合rabbitmq及rabbitmq的简单入门
查看>>
mysql事务和隔离级别笔记
查看>>
事务的传播属性(有坑点)自调用失效学习笔记
查看>>
REDIS缓存穿透,缓存击穿,缓存雪崩原因+解决方案
查看>>
动态代理实现AOP
查看>>