web項目獲取全路徑、端口、項目名等


文章轉自:https://blog.csdn.net/u010180031/article/details/52369537

在程序中我們一般這樣使用。說到了這里,我們可以看看request常用的方法:

       request.getSchema(),返回的是當前連接使用的協議,一般應用返回的是http、SSL返回的是https;

       request.getServerName(),返回當前頁面所在的服務器的名字;

       request.getServerPort(),返回當前頁面所在的服務器使用的端口,80;

       request.getContextPath(),返回當前頁面所在的應用的名字。

       getContextPath()是jsp中獲取路徑的一種方式,那么獲取到結果是什么呢?jsp其他獲取路徑的方式是怎樣的呢?表示好奇,請聽分解:

       以訪問的jsp為:http://localhost:8080/dmsd-itoo-exam-log-web/course/index.jsp,工程名為/dmsd-itoo-exam-log-web為例:

        request.getContextPath(),得到工程名:/dmsd-itoo-exam-log-web;

        request.getServletPath(),返回當前頁面所在目錄下全名稱:/course/index.jsp;

        request.getRequestURL(),返回IE地址欄地址:http://localhost:8080/dmsd-itoo-exam-log-web/course/index.jsp;

        request.getRequestURI() ,返回包含工程名的當前頁面全路徑:/dmsd-itoo-exam-log-web/course/index.jsp。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM