请求的分发和处理(区分GET和POST请求)
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
System.out.println("Hello,Servlet! 被访问了");
System.out.println("3.service方法");
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
String method = httpServletRequest.getMethod();
if ("POST".equals(method)){
doGet();
}else if ("GET".equals(method)){
System.out.println("GET请求");
}
}
public void doGet(){
System.out.println("POST请求");
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fb438daca71ee35569bc0098e99ff63f.png)