最近做了一个小的模块,让我对HttpServletRequest有了深刻的了解,此处记载我的体会:
- HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求数据的所有信息都封装在这个对象中,通过这个对象提供的方法,可以获得客户端请求的所有信息。
- 一开始我有两个盲点:
- reuqest只能获取请求头的数据
- request如何接受js对象
- getParamValues()获取接送数组
后来在实践中我才发现了这个问题 :首先引用HTTPServletRequest的官方描述
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data
string or posted form data可以接受请求头的 数据(url)也可接受HTTP请求的body数据.
request通过传递的数据格式key:value 通过请求头接受
对任何可以通过译者中格式传递的数据都可以接受,但是其在后端为一个字符串,我们需要对其解析
getParamValues()是为了获取name相等的元素,将其转为一个string[]数组 存储起来