卡通站,日本官方对亚投行作出表态,lgp970论坛
注:本博客参考了网上的文章结合自己工作总结后所写,主要用于记录自己工作所得,如有错误请批评指正.
content-type(mediatype),即是internet media type,互联网媒体类型;也叫做mime类型,在http协议消息头中,使用content-type来表示具体请求中的媒体类型信息.
response.header里常见content-type一般有以下四种:
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.
表单提交:
``` <form action="/test" method="post"> <input type="text" name="name" value="zhangsan"> <input type="text" name="age" value="12"> <input type="text" name="hobby" value="football"> </form> ```
后台:
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"; }
当post表单中有type=file控件时content-type会使用此编码方式.
表单提交:
``` <form action="/test" method="post" enctype="multipart/form-data"> <input type="text" name="name" value="zhangsan"> <input type="text" name="age" value="12"> <input type="text" name="hobby" value="football"> <input type="file" name="file1" </form> ```
后台:
@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"; }
随着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"; }
xml-rpc(xml remote procedure call)。它是一种使用 http 作为传输协议,xml 作为编码方式的远程调用规范。
soapui等xml-rpc请求的参数格式.
提交参数:
<arg0> <name>zhangsan</name> <age>12</age> <hobby>footbal</hobby> </arg0>
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论