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

怎么获取web项目的主路径

2011-12-14 
如何获取web项目的主路径比如web路径是c:\test\webroot\index.jsp要获取到 c:\test\webroot\ 网络上找的

如何获取web项目的主路径
比如web路径是
c:\test\webroot\index.jsp
要获取到 "c:\test\webroot\ "

网络上找的两个方法都不大好
this.getClass().getClassLoader().getResource( "/ ").getPath()
getServletContext().getRealPath( " ")
它们都是得到classes里的路径,而且第二个只能在servlet里用

[解决办法]
getServletContext().getRealPath();可以在JSP中找到指定的文件的真实路径
[解决办法]
getServletContext().getRealPath();

热点排行