Request_获取请求体数据
生活随笔
收集整理的這篇文章主要介紹了
Request_获取请求体数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?? ??? ?3. 獲取請求體數據:
?? ??? ??? ?* 請求體:只有POST請求方式,才有請求體,在請求體中封裝了POST請求的請求參數
?? ??? ??? ?* 步驟:
?? ??? ??? ??? ?1. 獲取流對象
?? ??? ??? ??? ??? ?* ?BufferedReader getReader():獲取字符輸入流,只能操作字符數據
?? ??? ??? ??? ??? ?* ?ServletInputStream getInputStream():獲取字節輸入流,可以操作所有類型數據
?? ??? ??? ??? ??? ??? ?* 在文件上傳知識點后講解
?? ??? ??? ??? ?2. 再從流對象中拿數據
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>注冊頁面</title> </head> <body><form action="/day12/requestDemo5" method="post"><input type="text" placeholder="請輸入用戶名" name="username"><br><input type="text" placeholder="請輸入密碼" name="password"><br><input type="submit" value="注冊"></form></body> </html> package com.learn.web.request;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.io.IOException;@WebServlet("/requestDemo5") public class RequestDemo5 extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//獲取請求消息體--請求參數//1.獲取字符流BufferedReader br = request.getReader();//2.讀取數據String line = null;while((line = br.readLine()) != null){System.out.println(line);}}protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {} }?
總結
以上是生活随笔為你收集整理的Request_获取请求体数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Request_获取请求头数据
- 下一篇: Request_获取请求参数通用方式介绍