80
技术社区[云栖]
J2EE中获得web路径和类路径总结
以工程名为TEST为例一、取得Web中的路径
/TEST/test.jsp
②工程名:request.getContextPath()
/TEST
③当前页面所在目录下全名称request.getServletPath()
若页面在jsp目录下/TEST/jsp/test.jsp
④页面所在服务器的全路径request.getSession().getServletContext().getRealPath("a.jsp");
D:\resin\webapps\TEST\test.jsp
若想定位到某个文件夹则getServletContext().getRealPath("WEB-INF");
getServletContext()其实取得的是application
⑤页面所在服务器的绝对路径:request.getSession().getServletContext().(request.getRequestURI()).getParent();
D:\resin\webapps\TEST
二、取得类路径
①类的绝对路径:Class.class.getClass().getResource("/").getPath()
/D:/TEST/WebRoot/WEB-INF/classes/pack/
②工程的路径:System.getProperty("user.dir")
D:\TEST
原帖地址:https://deific.iteye.com/blog/1172107
最后更新:2017-04-04 07:03:51
上一篇:
搜索的未来
下一篇:
Android 长按setOnItemLongClickListener 显示context Menu(上下文菜单)
Ruby 1.9概要(5) 异常
在64位机器上使用plSQL连接Oracle的问题(SQL*Net not properly installed)
Mysql Group Replication in Single-Primary Mode介绍及安装部署
[Qt教程] 第11篇 2D绘图(一)绘制简单图形
公历转农历函数
Greenplum failed segment的恢复方法
Java线程范围变量——ThreadLocal的模拟和解释
Java对象排序、中文排序、SortedSet排序使用和源码讲解
Universal Image Loader for Android 使用实例
Googler:现在可以 Linux 终端下进行 Google 搜索了!