来继承一下HttpServlet
public class FirstServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.service(req, resp);
}
@Override
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
super.service(req, res);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
}
有两个service方法
先走Servlet的service,然后走service(HttpServletRequest
然后根据请求方法来判断
如果是get方法,就走doGet
如果是post方法,就走doPost
如果没有复写get或者post
那么访问之后会405
因为如果没有被复写,那么父类默认返回405
405就是访问的路径不支持此方法(get或post)