您的位置:首页 > 运维架构 > Linux

有关Linux下request.getRealPath("/")获取路径的问题

2014-08-21 15:26 465 查看
request.getRealPath("/") 在window获取的是服务器的根目录,结尾包含分隔符,

如E:\apache-tomcat-6.0.29-bak\apache-tomcat-6.0.29\apache-tomcat-6.0.29\webapps\test\

在Linux下获取的不含分隔符,如:

/home/weblogic/Desktop/PTYT/ptytNetpay/WebRoot

因此需要判断处理:

String root = request.getRealPath("/");
if (!root.endsWith(java.io.File.separator)) {
root = root + java.io.File.separator;
}


最后 : request.getRealPath() 方法已经不推荐使用,推荐使用 request.getSession().getServletContext().getRealPath("/");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐