首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

怎么在java web项目后端项目中获取路径

2012-08-22 
如何在java web项目后端项目中获取路径1、获取类文件下的绝对路径 youClass.class.getResource(/).toStri

如何在java web项目后端项目中获取路径

1、获取类文件下的绝对路径

youClass.class.getResource("/").toString().replaceAll("file:/", "")

?

2、获取项目路径

getServletContext().getRealPath("/");

?

?3、获取类文件路径

this.getClass().getClassLoader().getResource("/").getPath();

?

4、获取项目路径

request.getContextPath();

?

5、获取项目路径
System.getProperty("user.dir")

?

6、获取顶级路径

new File("/").getAbsolutePath()

?

7、获取当前类路径

ClassLoader.getSystemResource("")

?

8、获取当前类路径

Thread.currentThread().getContextClassLoader().getResource("")

热点排行