当前位置: 代码迷 >> Web前端 >> weblogic war 途径 getServletContext().getRealPath() 和request.getRealPath
  详细解决方案

weblogic war 途径 getServletContext().getRealPath() 和request.getRealPath

热度:961   发布时间:2012-10-08 19:54:56.0
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();
上面这个是获取了web-inf/classes里面的路径,

也可以使用ServletContext.getResourceAsStream("/WEB-INF/config/db.config")方法。

  相关解决方案