Request 02Request_獲取請求數據

1. 獲取請求消息數據

1. 獲取請求行數據

            * GET /day14/demo1?name=zhangsan HTTP/1.1
            * 方法:
                1. 獲取請求方式 :GET
                    * String getMethod()  
                2. (*)獲取虛擬目錄:/day14
                    * String getContextPath()
                3. 獲取Servlet路徑: /demo1
                    * String getServletPath()
                4. 獲取get方式請求參數:name=zhangsan
                    * String getQueryString()
                5. (*)獲取請求URI:/day14/demo1
                    * String getRequestURI():        /day14/demo1
                    * StringBuffer getRequestURL()  :http://localhost/day14/demo1

                    * URL:統一資源定位符 : http://localhost/day14/demo1    中華人民共和國
                    * URI:統一資源標識符 : /day14/demo1                    共和國
                
                6. 獲取協議及版本:HTTP/1.1
                    * String getProtocol()

                7. 獲取客戶機的IP地址:
                    * String getRemoteAddr()
                

2. 獲取請求頭數據

            * 方法:
                * (*)String getHeader(String name):通過請求頭的名稱獲取請求頭的值
                * Enumeration<String> getHeaderNames():獲取所有的請求頭名稱
            

3. 獲取請求體數據:

            * 請求體:只有POST請求方式,纔有請求體,在請求體中封裝了POST請求的請求參數
            * 步驟:
                1. 獲取流對象
                    *  BufferedReader getReader():獲取字符輸入流,只能操作字符數據
                    *  ServletInputStream getInputStream():獲取字節輸入流,可以操作所有類型數據
                        * 在文件上傳知識點後講解

                2. 再從流對象中拿數據
            
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章