zoukankan      html  css  js  c++  java
  • java中获取项目在tomcat目录下的路径方法

    HttpServletRequest request

    //获取的是ROOT项目在tomcat下的路径

    方法1:

      String path = request.getSession().getServletContext().getRealPath("/");  

      path值如下:

      C:developapache-tomcat-7.0.75webappsROOT

    方法2:

      String path=System.getProperty("catalina.home");

      path值如下:

      C:developapache-tomcat-7.0.75

    /**
    * 根据图片路径,判断图片是否为空,如果不为空则看是否存在硬盘中,如果不存在则给默认图片,否则显示出该图片
    */
    String photo="/upload/noimg.png";
    String headSculpturePath = request.getSession().getServletContext().getRealPath("/upload")+"/"; //如:C:\develop\apache-tomcat-7.0.75\webapps\ROOT\upload
    String serverPath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();//如:http://localhost:9099
    if(!"".equals(torgcadre.getPhoto())&&torgcadre.getPhoto()!=null){
    File file = new File(headSculpturePath+torgcadre.getPhoto());
    if(!file.exists()){
    torgcadre.setPhoto(serverPath+photo);
    }else{
    torgcadre.setPhoto(serverPath+"/upload/"+torgcadre.getPhoto());
    }
    }else{
    torgcadre.setPhoto(serverPath+photo);
    }

  • 相关阅读:
    第07组 Beta冲刺(2/5)
    第07组 Beta冲刺(1/5)
    第07组 Alpha事后诸葛亮
    第07组 Alpha冲刺(5/6)
    第07组 Alpha冲刺(6/6)
    软工实践个人总结
    第01组 Beta版本演示
    第01组 Beta冲刺(5/5)
    第01组 Beta冲刺(4/5)
    第01组 Beta冲刺(3/5)
  • 原文地址:https://www.cnblogs.com/learnapi/p/7928069.html
Copyright © 2011-2022 走看看