赞
踩
问题:在weblogic war 路径 getServletContext().getRealPath()
和request.getRealPath,
weblogic获取路径总是为NULL,怎么破?????
通常情况下载tomcat中,我们以前使用 HttpServletRequest request;
request.getRealPath(arg0)
但是这是个方法已经过时了。。。。。。。。
request.getSession().getServletContext().getRealPath()
得到站点的绝对地址
HttpServletRequest request;
request.getSession().getServletContext().getRealPath(arg0);
在strut中通过
this.getServlet().getServletContext().getRealPath(arg0);
ServletActionContext.getServletContext().getRealPath(agr0)
在Servlet中通过 extends HttpServlet
this.getServletContext().getRealPath(arg0);
如果 weblogic里面war项目获取路径为空
对一个打包的应用来说,是没有RealPath的概念的,调用getRealPath只会简单地返回null——这就是问题!
那么可以这样破:
String
path=this.getClass().getClassLoader().getResource("/").getPath();
上面这个path路径,就是到web-inf/classes里面的路径,如果路径深了,可以截取
譬如:String pathxx = path.substring(0,path.indexOf("WEB-INF")
);
pathxx 这个路径就是到项目名称了。。。。。。。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。