zoukankan      html  css  js  c++  java
  • HandlerMapping执行流程

     .Spring MVC HandlerMapping  代码层面的执行流程

    1.web.xml中找到DispatcherServlet,ctrl+鼠标左键进入定义

    2.找到doDispatch()方法

    asynchronous:异步的
    synchronous:同步的


    //入参进来一个request
    protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {

            HttpServletRequest processedRequest = request;
           处理器执行链
            HandlerExecutionChain mappedHandler = null;
           多部分请求 解析器  (文件上传)
            boolean multipartRequestParsed = false;

            WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);

            try {
                try {
           模型(数据)和视图
                    ModelAndView err = null;
    异常
                    Exception dispatchException = null;

                    try {
       //指的是 DispatcherServlet 的实例  看看请求是不是多部分请求 


       <form  enctype="multipart/form-data">  表单有文件域 上传文件了

                        processedRequest = this.checkMultipart(request);

                        multipartRequestParsed = processedRequest != request;


    今天我们就探讨你 ,小子!!!!!!
                        mappedHandler = this.getHandler(processedRequest);


     3.    protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {

            handlerMappings单列集合 。Set   List  
            Iterator var2 = this.handlerMappings.iterator();
            HandlerExecutionChain handler;
                if(!var2.hasNext())    return null;
               每next()拿到一个HandlerMapping实例
                HandlerMapping hm = (HandlerMapping)var2.next();
                handler = hm.getHandler(request);
               return handler;
        }

        4.我们知道,HandlerMapping是一个接口 ,找实现类 Ctrl+H
           public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {

            Object handler = this.getHandlerInternal(request);
            if(handler == null) {
                handler = this.getDefaultHandler();
            }

            if(handler == null) {
                return null;
            } else {
                if(handler instanceof String) {
                    String handlerName = (String)handler;  //  /hello
                    handler = this.getApplicationContext().getBean(handlerName);
                }

                return this.getHandlerExecutionChain(handler, request);
            }
        }
  • 相关阅读:
    provider: Shared Memory Provider, error: 0
    用户 'sa' 登录失败。 (Microsoft SQL Server,错误: 18456)
    从sqlite 迁移到mysql报错,处理 D:seafile-server_5.0.3_win32seafile-server-5.0.3seahubsql 重新执行这个SQL
    org.apache.jasper.runtime.ELContextImpl cannot be cast to org.apache.jasper.el.ELContextImpl
    java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation
    无法完成操作。服务无法在此时接受控制信息。
    MyEclipse出现Unable to install breakpoint in...
    ERROR 1364 (HY000): Field 'id' doesn't have a default value
    各地都在搞大数据,你的家乡有啥特色没——解读2017年地方政府大数据报告
    HTML5桌面通知:notification
  • 原文地址:https://www.cnblogs.com/1234AAA/p/8617368.html
Copyright © 2011-2022 走看看