web專案獲取全路徑 埠 專案名等

2021-10-04 01:33:53 字數 1067 閱讀 1069

感謝大佬:

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.getrequesturi(),返回包含工程名的當前頁面全路徑:/dmsd-itoo-exam-log-web/course/index.jsp

servletcontext.getrealpath(string),為給定虛擬路徑返回包含實際路徑的 string

對jsp獲取當前應用的路徑方法和request常用方法有了基本的了解,下面後台通過request.getscheme()獲取當前頁面使用協議遇到的問題:

request.getschema()獲取到的確實http而不是https,與request.getrequesturl()拿到的一樣也是http。

原來,nginx+tomcat部署web服務,tomcat接收到的請求是來自nginx的http請求。我想這也是上一博文中說到專案用https啟動請求不到頁面的原因吧。

補充:

web專案獲取全路徑 埠 專案名等

感謝大佬 request.getschema 返回的是當前連線使用的協議,一般應用返回的是http ssl返回的是https request.getservername 返回當前頁面所在的伺服器的名字 request.getserverport 返回當前頁面所在的伺服器使用的埠,80 request...

Web專案獲取路徑的方法

equest.getrealpath 這個方法已經不推薦使用了,代替方法是 request.getsession getservletcontext getrealpath 在servlet裡用this.getservletcontect getrealpath 在struts裡用this.gets...

檔案過濾驅動 獲取全路徑名

第一部分 取全路徑 以下是獲取全路徑的所有函式 string操作參見字串操作的乙個庫unicode.lib record add by lwf 07 07 25 purpose get symbolic target unicode string pvoid spygetsymbolicunistr...