论坛首页 入门技术论坛

Tomcat 路径问题之web 头像

浏览 2662 次
该帖已经被评为新手帖
作者 正文
   发表时间:2010-02-07   最后修改:2010-02-24
我的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的这个目录下建立你想要的文件夹就可以了

也可以直接在工程下建立目录
   发表时间:2010-02-09  
servlet spe 写道
In situations where the servlet container cannot determine a valid file path for
these methods, such as when the Web application is executed from an archive, on
a remote file system not accessible locally, or in a database, these methods must
return null.

 所以getRealPath()最好不要用,像打成war包时会返回null

0 请登录后投票
   发表时间:2010-02-09  
flynofry 写道
servlet spe 写道
In situations where the servlet container cannot determine a valid file path for
these methods, such as when the Web application is executed from an archive, on
a remote file system not accessible locally, or in a database, these methods must
return null.

 所以getRealPath()最好不要用,像打成war包时会返回null

打包成WAR最后运行的时候不也要解压成文件夹的形式吗?有什么错?

0 请登录后投票
   发表时间:2010-02-09  
超级潜水艇 写道
flynofry 写道
servlet spe 写道
In situations where the servlet container cannot determine a valid file path for
these methods, such as when the Web application is executed from an archive, on
a remote file system not accessible locally, or in a database, these methods must
return null.

 所以getRealPath()最好不要用,像打成war包时会返回null

打包成WAR最后运行的时候不也要解压成文件夹的形式吗?有什么错?


好像有的容器不会自动解压WAR包的……
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics