初步修改项目

package com.hy.servlet;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.hy.utils.StringUtil; @WebServlet("/cs")
public class CoreServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String ac = request.getParameter("ac");
System.out.println("======="+ac+"======");
if (StringUtil.isEmpty(ac))
ac = "index"; // 获取当前类的所有方法
Method[] methods = this.getClass().getDeclaredMethods(); for (Method m : methods) {
// 获取方法名称
String methodName = m.getName();
if (ac.equals(methodName)) {
// 找到和ac同名的方法,那么通过反射技术调用它
try {
m.invoke(this, request, response);
return;
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
} throw new RuntimeException("ac值错误");
} private void index(HttpServletRequest request, HttpServletResponse response) {
System.out.println("aaaaaaaaaaa");
}
}

  

package com.hy.utils;

public class StringUtil {
//判断字符串是否为null或者""
public static boolean isEmpty(String str){
return str==null || "".equals(str);
} public static boolean isNotEmpty(String str){
return !isEmpty(str);
} }

成功

最新文章

  1. PHP扩展——C扩展实现滚动记录日志
  2. LevelDB源码分析--使用Iterator简化代码设计
  3. poj1979
  4. ubuntu16.04 编译安装mysql5.7.x,以及配置使用
  5. BeanDefinition的Resource定位——3
  6. trie树(前缀树)
  7. CSS的浮动和清除
  8. SqlBulkCopy的使用
  9. node.js 基础知识之 querystring.stringify querystring.escape
  10. 技术人应该学习的行话--UML统一建模语言
  11. Glide和Picasso的区别
  12. vue刷新当前路由
  13. 1.shell学习之常用语句
  14. C# 中BindingSource 的用法
  15. CRM 报表中 Filtered 无数据
  16. Word2007的自动插入题注!
  17. Spring WebSocket教程(二)
  18. LOJ 164 【清华集训2015】V——线段树维护历史最值
  19. layer的alert图
  20. 2018 徐州赛区网赛 G. Trace

热门文章

  1. Linux docker 安装nginx 配置ssl证书
  2. springboot集成xxl-job问题
  3. web基础(7): JavaScript 简介/语法
  4. html 1.0
  5. npm install报错C:\Users\Guyang\AppData\Roaming\npm-cache\_logs\xxx-14T01_06_33_159Z-debug-0.log
  6. 初学银河麒麟linux笔记 第四章 windows中开发的QT程序适配linux的修改——error: ‘QT_WARNING_DISABLE_DEPRECATED’ does not name a type
  7. linux下安装jdk8,nginx
  8. A - Yet Another Tetris Problem
  9. 【git】git基本使用以及设置
  10. 【根文件系统 】开发板通过nfs挂载ubuntu上的根文件系统