如题:
Method method = getClass().getDeclaredMethod ,getClass()前面省略的 “this. ” 是指的 CustomerServlet 吗?
JSP 页面源码:
以下是 CustomerServlet 源码:
@WebServlet(name="CustomerServlet",urlPatterns={"*.do"})
public class CustomerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String servletPath = req.getServletPath();
String methodName = servletPath.substring(1, servletPath.length()-3);
System.out.println(methodName);
try {
Method method = getClass().getDeclaredMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
method.invoke(this, req, resp);
} catch (Exception e) {
}
}
private void delete(HttpServletRequest request, HttpServletResponse response) {
System.out.println("delete");
}
private void query(HttpServletRequest request, HttpServletResponse response) {
System.out.println("query");
}
}