1、方法
[x]
//获取请求方式
`String method = request.getMethod();`<br /> `System.out.println(method);`
2、实现
```java package servlet;
import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.PrintWriter; import java.net.HttpCookie; import java.net.SocketTimeoutException;
/**
- @Author: 小雷学长
- @Date: 2022/3/20 - 17:22
@Version: 1.8 */ public class RequestTestServlet extends HttpServlet {
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//获取请求路径
String method = request.getMethod();
System.out.println(method);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print(method);
} }
RequestTestServlet servlet.RequestTestServlet RequestTestServlet /testrequest
```