zoukankan      html  css  js  c++  java
  • struts2-流程详解-StrutsPrepareAndExecuteFilter

    http://hi.baidu.com/liangzhongbo/item/07be3a560c16bc13da163536

    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

    初始化:

    public void init(FilterConfig filterConfig)
    throws ServletException
    {
    InitOperations init = new InitOperations();
    FilterHostConfig config = new FilterHostConfig(filterConfig);
    init.initLogging(config);
    Dispatcher dispatcher = init.initDispatcher(config);
    init.initStaticContentLoader(config, dispatcher);
    prepare = new PrepareOperations(filterConfig.getServletContext(), dispatcher);
    execute = new ExecuteOperations(filterConfig.getServletContext(), dispatcher);
    excludedPatterns = init.buildExcludedPatternsList(dispatcher);
    postInit(dispatcher, filterConfig);
    init.cleanup();
    break MISSING_BLOCK_LABEL_108;
    Exception exception;
    exception;
    init.cleanup();
    throw exception;
    }

    执行任务

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)

    throws IOException, ServletException
    {
    HttpServletRequest request;
    HttpServletResponse response;
    request = (HttpServletRequest)req;
    response = (HttpServletResponse)res;
    prepare.setEncodingAndLocale(request, response);

    /*为当前线程创建ActionContext,ActionContext是ThreadLocal的,ActionContent其实就是一个线程安全的HashMap,它内部使用一个HashMap

    来储存相关信息,这个map的构造是使用dispatcher.createContextMap(request, response, null, servletContext)来形成的,这个

    map包括的信息有session,request,response,ServletContext,RequestMap,SessionMap等各种信息,可以通

    个这个ActionContent取得各种信息,例如ActionContext.getContext().getSession()来获得当前的Session,

    如果要获得request或者response必须用ServletActionContext它是ActionContent的子类,提供更多的方法,如

    果是forward那也会新建一个新的ActionContent,这个新的ActionContent直接使用旧的ActionContent的数据来

    构造*/

    prepare.createActionContext(request, response);
    prepare.assignDispatcherToThread();
    if(excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns))
    {
    chain.doFilter(request, response);
    } else
    {
    request = prepare.wrapRequest(request);
    org.apache.struts2.dispatcher.mapper.ActionMapping mapping = prepare.findActionMapping(request, response, true);
    if(mapping == null)
    {
    boolean handled = execute.executeStaticResourceRequest(request, response);
    if(!handled)
    chain.doFilter(request, response);
    } else
    {
    execute.executeAction(request, response, mapping);
    }
    }
    prepare.cleanupRequest(request);
    break MISSING_BLOCK_LABEL_178;
    Exception exception;
    exception;
    prepare.cleanupRequest(request);
    throw exception;
    }

  • 相关阅读:
    JSP学习-JSP访问数据库-JavaBean封装
    JSP学习-sessionDemo
    第十次随笔
    第九次随笔
    第八次随笔
    第七次随笔
    第六次随笔
    第五次随笔
    第四次随笔
    第三次随笔
  • 原文地址:https://www.cnblogs.com/wangjianbg/p/3555857.html
Copyright © 2011-2022 走看看