当前位置: 代码迷 >> Web前端 >> Tomcat 路径有关问题之web 头像
  详细解决方案

Tomcat 路径有关问题之web 头像

热度:367   发布时间:2012-10-15 09:45:24.0
Tomcat 路径问题之web 头像
我的tomcat放到d盘下,项目名称为project,则:
System.out.println(request.getRealPath(""));
System.out.println(request.getContextPath());
      System.out.println(getServlet().getServletContext().getRealPath("/"));

    依次输出:
    d:\apache-tomcat-5.5.26\webapps\project
    /project
    d:\apache-tomcat-5.5.26\webapps\project\


在jsp页面中直接使用
   ${pageContext.request.contextPath}就可以找到
        C:\apache-tomcat-5.5.26\webapps\project\
只用在Tomcat的这个目录下建立你想要的文件夹就可以了

也可以直接在工程下建立目录
1 楼 flynofry 2010-02-09  
<div class="quote_title">servlet spe 写道</div>
<div class="quote_div">In situations where the servlet container cannot determine a valid file path for<br>these methods, such as when the Web application is executed from an archive, on<br>a remote file system not accessible locally, or in a database, these methods must<br>return null.</div>
<p>?所以getRealPath()最好不要用,像打成war包时会返回null</p>
2 楼 超级潜水艇 2010-02-09  
<div class="quote_title">flynofry 写道</div>
<div class="quote_div">
<div class="quote_title">servlet spe 写道</div>
<div class="quote_div">In situations where the servlet container cannot determine a valid file path for<br>these methods, such as when the Web application is executed from an archive, on<br>a remote file system not accessible locally, or in a database, these methods must<br>return null.</div>
<p>?所以getRealPath()最好不要用,像打成war包时会返回null</p>
</div>
<p>打包成WAR最后运行的时候不也要解压成文件夹的形式吗?有什么错?</p>
3 楼 hongyuan19 2010-02-09  
<div class="quote_title">超级潜水艇 写道</div><div class="quote_div"><div class="quote_title">flynofry 写道</div>
<div class="quote_div">
<div class="quote_title">servlet spe 写道</div>
<div class="quote_div">In situations where the servlet container cannot determine a valid file path for<br>these methods, such as when the Web application is executed from an archive, on<br>a remote file system not accessible locally, or in a database, these methods must<br>return null.</div>
<p>?所以getRealPath()最好不要用,像打成war包时会返回null</p>
</div>
<p>打包成WAR最后运行的时候不也要解压成文件夹的形式吗?有什么错?</p></div><br/>好像有的容器不会自动解压WAR包的……
  相关解决方案