package cn.itcast.travel.web.servlet;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class BaseServlet extends HttpServlet {
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
//
//1.获取请求路径
String uri = request.getRequestURI();
System.out.println(uri);
//2.获取方法名称
String methodName = uri.substring(uri.lastIndexOf(’/’) + 1);
System.out.println(“方法名称” + methodName);
//获取方法对象method
System.out.println(this);
try {
Method method = this.getClass().getMethod(methodName, HttpServletResponse.class, HttpServletRequest.class);
method.invoke(this, request, response);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}

报错
java.lang.NoSuchMethodException问题
方法都已修改public,仍然报错

java.lang.NoSuchMethodException问题

错位,参数无法传递

修改后ok

相关文章:

  • 2021-06-28
  • 2021-06-20
  • 2021-10-01
  • 2021-11-13
  • 2021-11-23
猜你喜欢
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2021-04-24
相关资源
相似解决方案