javaweb工程,Servlet里面获取当前WEB跟路径的文件绝对路径地址

时间:2022-08-26 15:33:08
String base_Url = request.getSession().getServletContext().getRealPath("/"); 
        String windows_path = "js\\weixin\\wxMenuTemplate.json";
        String linux_path = "js/weixin/wxMenuTemplate.json";
        String osName = System.getProperties().getProperty("os.name");
        String url = base_Url + (osName.equals("Window") ? windows_path : linux_path);
        log.info("=============generateMenu=====wxMenuTemplate.json url=================: "+url);
        //String tempUrl = "/home/application/tomcat11002-website/webapps/ROOT/js/weixin/wxMenuTemplate.json";
        String jsonStr=FileUtil.read(url,"UTF-8");