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()

  • 相关阅读:
    JavaSript模块化 && AMD CMD 详解.....
    js实现touch移动触屏滑动事件
    页面布局之BFC 微微有点坑
    前端代码优化
    HTTP消息头详解
    SASS
    移动互联,手机页面设计
    投身移动开发必须知道的20件事
    浅析HTML5在移动应用开发中的使用
    js数组的操作
  • 原文地址:https://www.cnblogs.com/it-xiaoJiang/p/5651865.html
Copyright © 2011-2022 走看看