当前位置:   article > 正文

weblogic中servlet报404_weblogic中ServletActionContext.getServletContext().getRealPath("/")空指针的解决...

weblogic中servlet报404_weblogic中ServletActionContext.getServletContext().getRealPath("/")空指针的解决...

问题:在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 这个路径就是到项目名称了。。。。。。。。。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/430391
推荐阅读
相关标签
  

闽ICP备14008679号