後端獲取URL和引數

2021-08-20 18:02:16 字數 992 閱讀 6716

一:獲取url

1.request.getrequesturl

返回的是請求的全部,包括http協議、埠號、servlet名字和對映路徑,但不包含請求引數。

結果:http://localhost:8080/jqueryweb/resources/request.html

2.request.getrequesturi

返回的是url的部分,即相對路徑。 結果

:/jqueryweb/resources/request.html

二: 獲取引數列表

1.getquerystring()

只適用於get,比如客戶端傳送http://localhost/testservlet?a=b&c=d&e=f,

通過request.getquerystring()得到的是a=b&c=d&e=f。之後再根據字串切割獲取想要的引數值。

2.getparameter()

get和post都可以使用,獲取的是括號裡的引數對應的值。

3.getinputstream()

4.getreader()

上面兩種方法獲取的是http請求包的包體,因為get方式請求一般不包含包體.所以上面兩種方法一般用於post請求獲取引數。

當form表單內容採用 enctype=multipart/form-data編碼時,即使先呼叫request.getparameter()也得不到資料,

所以這時呼叫request.getparameter()方法對 request.getinputstream()或request.getreader()沒有衝突,

即使已經呼叫了 request.getparameter()方法也可以通過呼叫request.getinputstream()或request.getreader()得到表單中的資料,

而request.getinputstream()和request.getreader()在同乙個響應中是不能混合使用的,如果混合使用就會拋異常。

上述部分**於:

獲取url引數

想要獲取url的引數,只要記住 url的引數是存在window.location.search中的,然後再根據引數的個數等特點用不同的方式擷取,或者匹配即可。方法一 正則法 function getquerystring name return null 呼叫 注 記得打引號 getquerystr...

獲取url引數

想要獲取url的引數,只要記住 url的引數是存在window.location.search中的,然後再根據引數的個數等特點用不同的方式擷取,或者匹配即可。方法一 正則法 function getquerystring name return null 呼叫 注 記得打引號 getquerystr...

獲取url引數

在當前頁面獲取從上乙個頁面傳過來的引數。如window.location.href ctp pages contractedit riskwarning.html?param param 注 如果傳遞過來的param是中文,就需要編碼window.location.href ctp pages co...