日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java contenttype_POST不同提交方式对应的Content-Type,及java服务器接收参数方式

發布時間:2023/12/1 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java contenttype_POST不同提交方式对应的Content-Type,及java服务器接收参数方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

簡介:

Content-Type(MediaType),即是Internet Media Type,互聯網媒體類型;也叫做MIME類型,在Http協議消息頭中,使用Content-Type來表示具體請求中的媒體類型信息.參考

response.Header里常見Content-Type一般有以下四種:

application/x-www-form-urlencoded

multipart/form-data

application/json

text/xml

詳解:

1.application/x-www-form-urlencoded

application/x-www-form-urlencoded是最常見的Content-Type,form表單默認提交方式對應的content-type.

當action為get時候,瀏覽器用x-www-form-urlencoded的編碼方式把form數據轉換成一個字串(name1=value1&name2=value2...),然后把這個字串追加到url后面,用?分割,加載這個新的url.

當action為post,且表單中沒有type=file類型的控件時,Content-Type也將采用此編碼方式,form數據將以key:value鍵值對的方式傳給server.

表單提交:

后臺:

import java.io.Serializable;

public class Student implements Serializable {

private String name;

private String hobby;

private int age;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getHobby() {

return hobby;

}

public void setHobby(String hobby) {

this.hobby = hobby;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

}

@RequestMapping(value = "/test", method = RequestMethod.POST)

public String test(Student student) {

System.out.println(student.getName());

return "/test1";

}

2.multipart/form-data

當post表單中有type=file控件時content-type會使用此編碼方式.

表單提交:

后臺:

@RequestMapping(value = "/test", method = RequestMethod.POST)

public String test(Student student,@RequestParam(value = "file1", required = false) MultipartFile file1) {

System.out.println(student.getName());

return "/test1";

}

3.application/json

隨著json規范的流行,以及前后端分離趨勢所致,該編碼方式被越來越多人接受.

前后端分離后,前端通常以json格式傳遞參數,因此該編碼方式較適合RestfulApi接口.

前端傳參:

$.ajax({

url: '/test',

type: 'POST',

data: {

"name": "zhangsan",

"age": 12,

"hobby": "football"

},

dataType: "json",

success: function (date) {

}

})

后臺:

@RequestMapping(value = "/test", method = RequestMethod.POST)

public String test(@RequestBody Student student) {

System.out.println(student.getName());

return "/test1";

}

4.text/xml

XML-RPC(XML Remote Procedure Call)。它是一種使用 HTTP 作為傳輸協議,XML 作為編碼方式的遠程調用規范。

soapUI等xml-rpc請求的參數格式.

提交參數:

zhangsan

12

footbal

分類: java

總結

以上是生活随笔為你收集整理的java contenttype_POST不同提交方式对应的Content-Type,及java服务器接收参数方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。