package com.lmlm.dbutils;
import java.io.IOException;
import java.lang.reflect.Method;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
// Servlet 里面的类直接继承这个类
public class BaseServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
// 获访问的方法名
String method = req.getParameter("method");
// 获取调用对象字节码文件
Class<? extends BaseServlet> claz = this.getClass();
try {
// 获取方法
Method method2 = claz.getMethod(method, HttpServletRequest.class, HttpServletResponse.class);
// 调用方法
method2.invoke(claz.newInstance(), req, resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}