HttpServletRequest常用的方法

2021-08-30 05:02:23 字數 1698 閱讀 7637

通過request物件得到客戶端url方法如下:

[list]

[1]、request.getrequesturl:[color=red]客戶請求的url,不包括引數資料。

[2]、request.getrequesturi:[color=red]/cbice/boardaction.do[/color]--------將url的網域名稱和尾隨的引數擷取掉,剩下的那部分就是uri 。

[3]、request.getcontextpath:[color=red]/cbice[/color]-----即斜桿加工程名。

[4]、request.getrealpath("/web-inf"):[color=red]d:\jboss-4.0.2_cbiceportal\server\default\.\deploy\user.war\web-inf[/color]-----即斜桿加工程名。

[5]、request.getmethod:[color=red]post[/color]--------http請求的的方法名,預設是get,也可以指定put或post。

[6]、request.getscheme: [color=red]http[/color] ---返回請求的方案名,如http,ftp,https等。

[7]、request.getservletpath: [color=red]/boardaction.do[/color]---工程之後到引數之前的這部分字串。

[8]、request.getservername: [color=red]user.cbice.com[/color] ---伺服器主機名。

[9]、request.getserverport: [color=red]80[/color] ---伺服器上web應用的訪問埠。

[10]、request.getremoteaddr: [color=red]192.168.6.8 [/color]---傳送請求的客戶端主機的ip

[11]、request.getremotehost: [color=red]192.168.6.8[/color] ---傳送請求的客戶端主機名,如果不確定返回的是ip。

[12]、request.getquerystring:[color=red]operation=dosearch&index=index&boardindex=boardindex[/color]------返回url上的引數部分的字串,必須是get的請求才有效,不然報錯.

[color=green]這裡的url引數中帶有中文,是通過字元轉碼的:string equery=new string(request.getquerystring().getbytes("iso-8859-1"))

response的響應內容:response.setcontenttype("text/html;charset=gbk"),才可以正常顯示頁面中文。

如果需要獲得引數則用string status = new string(request.getparameter("username").trim().getbytes(), "gbk");獲得其內容。

另外一種方法是:用string equery=urlencoder.encode("中文","gbk");按照引數編碼格式進行轉碼,

在頁面中通過request.getparamter("equery")得到的引數是中文,但是在url中顯示的是16進製制或其他進製的編碼。[/color][/list]

HttpServletRequest常用的方法

1 假設客戶端位址是 通過request物件得到客戶端url方法如下 1 request.getrequesturl 客戶請求的url,不包括引數資料。2 request.getrequesturi cbice boardaction.do 將url的網域名稱和尾隨的引數擷取掉,剩下的那部分就是ur...

selenium webdriver 常用方法

1 獲得頁面的原始碼 driver.get source code driver.getpagesource 如果想將獲得的網頁原始碼儲存成檔案的話 f open r c html source code.html w f.write source code.encode utf 8 f.close...

ConcurrentHashMap 常用方法

void clear 從該對映中移除所有對映關係 boolean containskey object key 測試指定物件是否為此表中的鍵。boolean containsvalue object value 如果此對映將乙個或多個鍵對映到指定值,則返回 true。enumeration elem...