问题描述
org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [UserServlet] in context with path [/TheWakingOfInsects] threw exception
java.lang.RuntimeException~~~~
相关代码
public class BaseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
//获取方法名称
String mName = request.getParameter("method");
//判断 参数是否为空 若为空,执行默认的方法
if(mName == null || mName.trim().length()==0){
mName = "index";
}
//获取方法对象
Method method = this.getClass().getMethod(mName, HttpServletRequest.class,HttpServletResponse.class);
//让方法执行,接受返回值
String path=(String) method.invoke(this, request,response);
//判断返回值是否为空 若不为空统一处理请求转发
if(path != null){
request.getRequestDispatcher(path).forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
}~~~~
问题描述信息过少, 估计是使用反射调用方法的返回值你进行强转为string类型,类型不一致无法强转抛出异常,自己捕获了,然后又在catch 里面抛出个运行时异常。