springMvc和struts配置文件实现方法的原理

记录一下个人见解:

springMvc:

通过扫描结合@RequestMapping找到方法,实现方法,至于处理器和适配器不多说

struts:

由配置文件(应该是通过正则表达式结合配置文件解析的url)获取要实现的类全名称以及方法名,结合反射方法的invoke()来实现方法,下面是servlet结合反射实现方法的类似调用。

String message = request.getParameter("method");
        if (message == null || message == "") {
            throw new RuntimeException("请求的资源不能为空!");
        }
        try {
            // 获取方法对象
            Method method = this.getClass().getMethod(message, HttpServletRequest.class, HttpServletResponse.class);
            // 调用方法
            method.invoke(this, request, response);//返回值
        } catch (Exception e) {
            e.printStackTrace();
        }

猜你喜欢

转载自blog.csdn.net/ryuhfxz/article/details/81675688