定义一个基类,继承HTTPServlet,重写service方法
public class BaseServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//接收从jsp页面传过来的要操作数据库的方法(增删改查,add,delete,update,select)
String method = request.getParameter("method");
//得到接收jsp页面请求的Servlet的字节码文件(也就是继承BaseServlet的子类)
Class clazz = this.getClass();
//如果method为null或者为"",就给他一个默认的index()方法
if (method == null || method.trim().length() == 0){
method = "index";
}
try {
//通过反射,得到Servlet中的对应方法
Method m = clazz.getMethod(method, HttpServletRequest.class, HttpServletResponse.class);
//执行方法,返回一个路径的字符串格式
String path = (String) m.invo