@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
System.out.println("this is hello servlet");
//HttpServletRequest是 ServletRequest的子类
HttpServletRequest httpServletRequest = (HttpServletRequest) req;
// getMethod()方法可以获取当前的请求类型
String method = httpServletRequest.getMethod();
System.out.println("请求类型: "+ method);
}
- HttpServletRequest是ServletRequest 的子类,子类有getMethod()方法可以获取当前的请求类型