從request物件中可以獲取各種路徑資訊,以下例子:
假設請求的頁面是index.jsp,專案是webdemo,則在index.jsp中獲取有關request物件的各種路徑資訊如下
string path = request.getcontextpath();
string basepath =request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";
string remoteaddress=request.getremoteaddr();
string servletpath=request.getservletpath();
string realpath=request.getrealpath("/");
string remoteuser=request.getremoteuser();
string requesturi=request.getrequesturi();
out.println("path:"+path+"
");
out.println("basepath:"+basepath+"
");
out.println("remoteaddr:"+remoteaddress+"
");
out.println("servletpath:"+servletpath+"
");
out.println("realpath:"+realpath+"
");
out.println("remoteuser:"+remoteuser+"
");
out.println("requesturi:"+requesturi+"
");
結果:
從上不難看出request各個對應方法所代表的含義
request獲取路徑
從request物件中可以獲取各種路徑資訊,以下例子 假設請求的頁面是index.jsp,專案是webdemo,則在index.jsp中獲取有關request物件的各種路徑資訊如下 string path request.getcontextpath string basepath request....
request獲取路徑
從request物件中可以獲取各種路徑資訊,以下例子 假設請求的頁面是index.jsp,專案是webdemo,則在index.jsp中獲取有關request物件的各種路徑資訊如下 string path request.getcontextpath string basepath request....
request 獲取各種路徑
從request獲取各種路徑總結 request.getrealpath url 虛擬目錄對映為實際目錄 request.getrealpath 網頁所在的目錄 request.getrealpath 網頁所在目錄的上一層目錄 request.getcontextpath 應用的web目錄的名稱 如...