学到了 总是忘记 记录一下
父类:
public class baseServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
String method = req.getParameter("method");
Class clazz = this.getClass();
}
子类:
@WebServlet("/oa/DeptServlet")
public class DeptServlet extends baseServlet {}
父类中的this.getClass()中的this指的是调用此方法的子类 寻找子类的service方法 没有 去父类中寻找在子类中调用的此service方法



