美文网首页
Spring 获取web路径

Spring 获取web路径

作者: 咖啡机an | 来源:发表于2018-11-08 12:20 被阅读0次

无request时

WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
       ServletContext servletContext = webApplicationContext.getServletContext();
       //文件的路径
       String strFilePath = servletContext.getRealPath("/").replace("rest", "web") + CommonConstant
               .FILE_TEMP_FOLDER;

有request时

//文件的名称
        String absoluteStrFilePath = request.getServletContext().getRealPath("/").replace("rest", "web") +
                CommonConstant.FILE_TEMP_FOLDER;
        relativeFileUrl = request.getContextPath().replace("rest", "web") +
                "/" + CommonConstant.FILE_TEMP_FOLDER + "/" + fileName;

相关文章

网友评论

      本文标题:Spring 获取web路径

      本文链接:https://www.haomeiwen.com/subject/obtwxqtx.html