/**
*
* Returns the name of the HTTP method with which this
* request was made, for example, GET, POST, or PUT.
* Same as the value of the CGI variable REQUEST_METHOD.
*
* @return a <code>String</code>
* specifying the name
* of the method with which
* this request was made
*
*/
public String getMethod();
请问HttpServletRequest中的这个方法是如何拿到请求方法的类型的,比如是get还是post
引用 皆我百晓生 小程序回复内容作答:
HttpServletRequest中的getMethod()方法用于获取发起请求时所使用的HTTP方法类型,例如GET、POST或PUT等。
具体实现是通过解析HTTP请求报文中的请求行来获取请求方法类型。在HTTP请求报文的第一行中,包含了请求方法、请求URI和HTTP协议版本。getRequestMethod()方法会解析这个请求行,并返回其中的请求方法。
例如,如果使用GET方法发送一个HTTP请求,那么getRequestMethod()方法将返回"GET"。如果使用POST方法发送一个HTTP请求,那么getRequestMethod()方法将返回"POST"。
【相关推荐】
post请求中用户输入的内容被放在请求体内,
html文件method方式修改为post
class文件中重写post方法