關於路徑拼裝的解釋

2021-07-14 00:00:25 字數 807 閱讀 4110

<%

string path = request.getcontextpath();

string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";

%>

這個語句是用來拼裝當前網頁的相對路徑的。

是用來表明當前頁面的相對路徑所使用的根路徑的。

比如,頁面內部有乙個連線,完整的路徑應該是 http://localhost:80/myblog/authen/login.do

其中http://server/是伺服器的基本路徑,myblog是當前應用程式的名字,那麼,我的根路徑應該是那麼http://localhost:80/myblog/。

有了這個 以後,我的頁面內容的連線,我不想寫全路徑,我只要寫 authen/login.do就可以了。伺服器會自動把 指定的路徑和頁面內的相對路徑拼裝起來,組成完整路徑。

如果沒有這個 ,那麼我頁面的連鏈結就必須寫全路徑,否則伺服器會找不到。

request.getschema()可以返回當前頁面使用的協議,就是上面例子中的「http」

request.getservername()可以返回當前頁面所在的伺服器的名字,就是上面例子中的「localhost"

request.getserverport()可以返回當前頁面所在的伺服器使用的埠,就是80,

request.getcontextpath()可以返回當前頁面所在的應用的名字,就是上面例子中的myblog

這四個拼裝起來,就是當前應用的跟路徑了

拼裝網頁路徑

string path request.getcontextpath string basepath request.getscheme request.getservername request.getserverport path 這個語句是用來拼裝當前網頁的相對路徑的。是用來表明當前頁面的相對...

拼裝當前網頁的相對路徑

先放 string path request.getcontextpath string basepath request.getscheme request.getservername request.getserverport path 下面解釋一下 的作用 request.getcontext...

關於的解釋

viewport 語法介紹 height pixel value device height width pixel value device width initial scale float value minimum scale float value maximum scale float ...