Servlet中的ServletContext
来源:互联网 发布:足彩软件哪个好 编辑:程序博客网 时间:2024/06/10 17:01
1.ServletContext的生命周期,随软件发行或上线而存在,随软件卸载或停用而消失。
2.ServletContext主要应用于拿到路径,或拿到加载参数
1 拿到web.xml中配置的driver路径
ServletContext servletContext = this.getServletContext();String driver = servletContext.getInitParameter("driver");System.out.println(driver);
2.拿到webContent下的a.txtString aPath = servletContext.getRealPath("/a.txt");System.out.println(aPath);
3拿到web-inf下的b.txt的路径String bPath = servletContext.getRealPath("/WEB-INF/b.txt");System.out.println(bPath);
4.拿到src下的c.txt路径String cPath = servletContext.getRealPath("/WEB-INF/classes/c.txt");System.out.println(cPath);
//在读取src(classes)下的资源是可以同类加载器 ----专门加载classes 下的文件的//getResource("")也是一个相对地址,相对于classes的String path = ContextServlet.class.getClassLoader().getResource("c.txt").getPath();System.out.println(path);
3.同时也可在servletContext中存储公共变量
阅读全文
0 0
- Servlet中的ServletContext对象
- Servlet中的ServletContext
- Servlet中的ServletContext
- Servlet中的ServletContext
- 如何使用servlet中的ServletContext
- Servlet 中的 Cookie 、 Session 和 ServletContext
- servlet中的知识点1:servletConfig,ServletContext
- servlet中的cookie、session、servletContext简单操作
- Servlet技术中的对象-ServletConfig与ServletContext
- servlet中的第一个域对象ServletContext
- Servlet中的ServletContext和ServletConfig详解
- Servlet:ServletContext
- Servlet ServletContext
- [servlet] ServletContext
- jsp中的application对象相当于Servlet中的 ServletContext
- Servlet之ServletContext读取web应用中的资源文件
- JavaWeb(一)Servlet中的ServletConfig与ServletContext
- javax.servlet.ServletContext接口
- React Native是怎么在Android上跑起来的
- activiti学习--13:组任务分配方式2--使用流程变量
- 《GNU_Octave_Beginner_s_Guide》读书笔记3:函数与绘图
- 【美图-选择题考点整理-第二篇】
- simhash 文本相似度计算
- Servlet中的ServletContext
- Trafodion Troubleshoot-SQScratchFile 3 System Error 2
- 如何查看网站服务器的地址
- 在使用easyui数据网格过程中遇到的问题
- 2934:字符串插入
- 9月6日云栖精选夜读:DMS前后端技术揭秘及最佳实践
- C语言基础 6 数组
- Ubuntu 14.04设置Proxy
- openshift/origin学习记录(1)——基于二进制文件的安装(单机版)