servlet獲取http接口獲取請求體內容(get&post)

  1. get請求方式:
	Long houseId = Long.parseLong(request.getParameter("houseId"));
  1. post請求方式
        ServletInputStream servletInputStream = request.getInputStream();

        StringBuilder content = new StringBuilder();
        byte[] b = new byte[1024];
        int lens;
        while ((lens = servletInputStream.read(b)) > 0) {
            content.append(new String(b, 0, lens));
        }
        
        String strContent = content.toString(); // 請求體內容

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章