serverwebexchange获取请求体_获取请求体数据

将一些获取请求体数据,请求体数据post请求的时候才有

serverwebexchange获取请求体_获取请求体数据_第1张图片




注册页面


	


package cn.itcast.servlet.request;

import java.io.BufferedReader;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class RequestDemo6
 */
@WebServlet("/requestDemo6")
public class RequestDemo6 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RequestDemo6() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	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);
		}
		
	}

}
serverwebexchange获取请求体_获取请求体数据_第2张图片
https://www.zhihu.com/video/1241418676949196800

你可能感兴趣的:(serverwebexchange获取请求体_获取请求体数据)