//JSP中
            <%
            out.println("根目錄所對應的絕對路徑:"  +  request.getRequestURI()  +  "<br/>");
              
            String  strPathFile  =  application.getRealPath(request.getRequestURI()); 
            out.println("文件的絕對路徑:"  +  strPathFile +  "<br/>");

            String  strDirPath  =  new  File(application.getRealPath(request.getRequestURI())).getParent(); 
            out.println("目錄的絕對路徑:"  +  strDirPath  +  "<br/>");
            %>

           

             //Servlet中 
             //JSP中的application對象就是Servlet中的ServerContext,所以在Servlet中是如此獲得 
              System.out.println("根目錄所對應的絕對路徑:"  +  request.getServletPath());

              String  strFullPath  =  request.getSession().getServletContext().getRealPath("");
              System.out.println("目錄的絕對路徑" + strFullPath);

              String  strContextPath  =  request.getContextPath(); 
              System.out.println("獲得Web項目的上下文路徑" + strContextPath);

              System.out.println("獲取訪問站點的相對路徑" + request.getRequestURI());
                 
              System.out.println("獲取訪問站點的絕對路徑" + request.getRequestURL());

          posts - 1, comments - 3, trackbacks - 0, articles - 7

          Copyright © wind_miao

          主站蜘蛛池模板: 宜阳县| 静宁县| 梓潼县| 白沙| 微博| 桑植县| 铜川市| 新平| 响水县| 常德市| 定西市| 依兰县| 洪洞县| 吉安县| 壤塘县| 贵德县| 响水县| 安化县| 南岸区| 黄冈市| 万宁市| 开江县| 蓝山县| 武鸣县| 海安县| 镇沅| 马龙县| 新沂市| 西贡区| 项城市| 文水县| 吉木乃县| 荣昌县| 江城| 宁海县| 怀远县| 喜德县| 紫阳县| 镇沅| 青河县| 博客|