使用servlet登陆时会出现错误,但是注册是没有问题的

新手上路,请多包涵

问题描述

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();
    }
}~~~~

实际看到的错误信息又是什么?

阅读 1.8k
1 个回答

问题描述信息过少, 估计是使用反射调用方法的返回值你进行强转为string类型,类型不一致无法强转抛出异常,自己捕获了,然后又在catch 里面抛出个运行时异常。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题