package web;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
public abstract class BaseServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action=request.getParameter("action");
try {
//获取action业务识别字符串,获取相应的业务方法反射对象
Method declaredMethod = this.getClass().getDeclaredMethod(action, HttpServletRequest.class,
HttpServletResponse.class);
declaredMethod.invoke(this,request,response);
//调用目标业务方法
}catch (Exception e){
e.printStackTrace();
throw new RuntimeException(e);//把异常抛给过滤器
}
}
}