zoukankan      html  css  js  c++  java
  • 民宿项目知识_服务器路径与文件的存储

    1,文件的硬盘存储路径(文件存放在服务器的根目录,而不是项目,防止服务器重启,资源丢失)

      得到项目的名字:如,renli

        String path1 = request.getContextPath();
        path1=path1.substring(1);

      得到项目的绝对路径:如,F:apache-tomcat-8.0.33webapps enliresources

         String path2 = request.getSession().getServletContext().getRealPath("");

      得到服务器的根目录:如,F:apache-tomcat-8.0.33webapps     

         String path2 = request.getSession().getServletContext().getRealPath("").replace(path1, "");
         path2=path2.substring(0, path2.length()-1)+"resources";

    2,资源的网络访问路径:http://localhost:8080/resources

         String url = "http://" + request.getServerName()+ ":" + request.getServerPort()+"/resources";

    3,截取文件名:

      String prefix = fileName.substring(fileName.lastIndexOf(".") + 1);

      UUID uuid = UUID.randomUUID();
      fileName = uuid + "." + prefix;

    4,判断file为空

      file.isEmpty()

  • 相关阅读:
    php -- 魔术方法 之 对象输出 : __toString()
    php -- each()、list()
    php -- 魔术方法、魔术常量 简单介绍
    webbench
    md5sum/opensll md5
    shopt
    MD5
    print显示特定的数据格式
    gdb调试4--回退
    字符串化#、拼接字符##和可变参数宏(...和_ _VA_ARGS_ _)
  • 原文地址:https://www.cnblogs.com/it-xiaoJiang/p/5651865.html
Copyright © 2011-2022 走看看