請求:
請求行:
1.get方式,請求引數放在請求行上,需要乙個乙個轉。
new string(ss.getbytes(「iso8859-1」),」utf-8」);
因為行、頭 字符集固定為iso8859-1
post方式,請求引數放在請求體重,只需要修改請求體的字符集為utf-8即可
request.setcharacterencoding(「utf-8」);
注意:請求體字符集設定,必須放在讀取請求體內容之前。getparameter這類方法之前,否則無效
2.string getmethod() 該方法用於獲取http請求訊息中的請求方式(如get、post等)
3.string getrequesturi() 該方法用於獲取請求行中資源名稱部分,即位於url的主機和埠之後、引數部分之前的部分
4.string getcontextpath() 該方法用於獲取請求url中屬於web應用程式的路徑,這個路徑以「/」開頭,表示相對於整個web站點的根目錄,路徑結尾不含「/」。如果請求url屬於web站點的根目錄,那麼返回結果為空字串(」」)
動態獲取當前的專案名
例如:/web12_1
5.string getremoteaddr() 該方法用於獲取請求客戶端的ip位址,其格式類似於「192.168.0.3」
localhost
127.0.0.1
0:0:0:0:0:0:0:1
------------------
請求頭:
request操作請求頭
方法宣告 功能描述
string getheader(string name) 該方法用於獲取乙個指定頭字段的值,如果請求訊息中沒有包含指定的頭字段,getheader()方法返回null;如果請求訊息中包含有多個指定名稱的頭字段,getheader()方法返回其中第乙個頭字段的值
響應:響應行: 響應狀態碼
response.setstatus(int status);
response.senderror(int status,string msg);//設定錯誤狀態碼4xx,5xx時,會將錯誤資訊顯示出來
響應頭:
response.setheader(string name,string value);//設定響應頭 如果name相同,新值覆蓋舊值
響應頭是可以自定義,但是沒有意義
name忽略大小寫的
response.addheader(string name,string value);//追加響應頭 如果name相同,值進行追加操作
重定向操作:【多練】
狀態碼:302
響應頭:location【已經被response.sendredirct(request.getcontextpath()+"/register.htm"(路徑名稱)取代】
3、 響應體
位元組流:getoutputstream();
字元流:getwriter();
string path = this.getservletcontext().getrealpath("/")+"download/"+file_name;
fileinputstream fis = new fileinputstream(path);
servletoutputstream out = response.getoutputstream();
注意:①一山難容二虎(乙個響應體中,不能同時用多個流操作)
②無論是response的位元組流還是字元流不需要咱們手動關閉的,由伺服器託管。
③重新整理流,建議使用response.flushbuffer();
問題1:乙個servlet**能否同時存在兩種流的**?沒問題
if(***)else
修改響應體字符集,同時修改前端解碼字符集
response.setcontenttype("text/html;charset=utf-8");
Burpsuite設定攔截response
一 burpsuite設定攔截http https 1,攔截修改request 首先進入proxy options intercept client requests設定request攔截的規則 如果不勾選intercept requests based on the following rules...
request和requestScope的區別
1 request物件通常用來接收從客戶端通過表單提交過來的資料,然後在servlet或者action中用request.getparameter 的方法獲取獲取引數內容 2 而requestscope通常是在servlet和action中通過request.setattribute 方法把資料放到...
Respons功能介紹 重定向以及特點
respons物件 功能 設定響應訊息 1.設定響應行 1.格式 http 1.1 200 ok 2.設定狀態碼 setstatus int sc 2.設定響應頭 setheader string name,string value 3.設定響應體 使用步驟 1.獲取輸出流 符輸出流 只能輸出字元資...