HttpServlet类中有两个service()方法 HttpServlet源码在Tomcat的jar包中。
public void service(ServletRequest req, ServletResponse res) throws ServletException,IOException{...};
Protect void service(HttpServiceRequest req, HttpServletResponse resp) throws ServletException,IOException {...}
调用时用公用的service方法去调用受保护的service方法。
HttpServlet类中定义如下:
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String method = req.getMethod(); if (method.equals(METHOD_GET)) { long lastModified = getLastModified(req); if (lastModified == -1) { // servlet doesn't support if-modified-since, no reason // to go through further expensive logic doGet(req, resp); } else { ........
}
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { HttpServletRequest request; HttpServletResponse response; try { request = (HttpServletRequest) req; response = (HttpServletResponse) res; } catch (ClassCastException e) { throw new ServletException("non-HTTP request or response"); } service(request, response); }