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 methodName = req.getParameter("method");
//如果method传递的参数为null或者为空字符串,作出提示
if(methodName == null || "".equals(methodName)){
resp.getWriter().println("method参数为null!!!");
return;
}
// 获得子类的Class对象:
/**
* this.class代表加载继承了这个BaseServlet的class对象
* */
Class clazz = this.getClass();
// 获得子类中的方法了:
try {
Method method = clazz.getMethod(methodName, HttpServletRequest.class,HttpServletResponse.class);
// 使方法执行,并获取子类return的字符串
String path = (String)method.invoke(this, req,resp);
//转发
if(path != null){
req.getRequestDispatcher(path).forward(req, resp);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

最新文章

  1. 三维网格精简算法(Quadric Error Metrics)附源码
  2. URL(统一资源定位符)结构和注意事项
  3. 和为S的连续正数序列
  4. html 字体加粗
  5. for update造成的Oracle锁表与解锁
  6. ***mysql索引总结----mysql索引类型以及创建
  7. VC MFC 屏蔽ESC和ENTER键关闭对话框
  8. git指令总结
  9. 将String转换为其表示的路径画到屏幕上
  10. docker中镜像的提交和上传
  11. xamarin.forms之使用CarouselView插件模仿网易新闻导航
  12. mysql 关于数据库和数据表的基本操作
  13. springboot下整合redis使用redisTemplate模板
  14. TensorFlow学习笔记之--[compute_gradients和apply_gradients原理浅析]
  15. SharePoint Framework 构建你的第一个web部件(一)
  16. 数据集 过滤时 RecordCount 属性
  17. 【Spring学习笔记-MVC-17】Spring MVC之拦截器
  18. C#实体更新指定的字段
  19. MR案例:MR和Hive中使用Lzo压缩
  20. Java初学者 编译能通过,但显示有错误,并且不会自动弹出方法的解决方法。

热门文章

  1. 机器学习基础梳理—(accuracy,precision,recall浅谈)
  2. Eugeny and Array(思维)
  3. sql server获取查询时间
  4. 每天进步一点点------altium designer Summer09出现的问题解决方案
  5. Kali部署DVWA和OWASPBWA
  6. chomp/undef/标量 --Perl 入门第二章
  7. 极客从CPU选择开始-CPU详解
  8. 如何用 Python 实现超级玛丽的人物行走和碰撞检测?
  9. ehcache注解全面解析
  10. PTA的Python练习题(十七)