学到了 总是忘记 记录一下
父类:
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");
/****this:谁调用的this就是谁 此service方法是BaseServlet的子类调用的 故this.getClass()指向的类就是DeptServlet***/
Class clazz = this.getClass();
}
子类:
@WebServlet("/oa/DeptServlet")
public class DeptServlet extends BaseServlet {}
父类中的this.getClass()中的this指的是调用此方法的子类 寻找子类的service方法 没有 去父类中寻找在子类中调用的此service方法