STRUS2 Study Notes-process

Source: Internet
Author: User

Starting STRUTS2 requires a filter to be configured in Web. XML:

<filter> <filter-name>action</filter-name> <filter-class> ORG.APACHE.STRUTS2.DISPATC Her.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> < Filter-name>action</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

When a user sends a request from the browser to the server, it first passes through the filter: Strutsprepareandexecutefilter

 //initialization, primarily instantiation of prepare and execute Dispathcher public void init (filterconfig filterconfig)  throws ServletException {              .             .                dispatcher =  Init.initdispatcher (config);             prepare  = new prepareoperations (Filterconfig.getservletcontext (),  dispatcher);//             execute = new executeoperations ( Filterconfig.getservletcontext (),  dispatcher);             this.excludedpatterns = init.buildexcludedpatternslist (Dispatcher);              postinit (dispatcher, filterconfig);//The method is empty, mainly left to developers to expand              .            .                      }    //     public void dofilter ( Servletrequest req, servletresponse res, filterchain chain)  throws  Ioexception, servletexception {        httpservletrequest  request =  (HttpServletRequest)  req;         httpservletresponse response =  (HttpServletResponse)  res;         try {        //Direct Release if user requests do not reach the action              if  (excludedpatterns != null && prepare.isurlexcluded ( Request, excludedpatterns))  {                 chain.dofilter (Request, response);             } else {                 prepare.setencodingandlocale (Request, response);                  Prepare.createactioncontext (request, response);//Create  actioncontext                 prepare.assigndispatchertothread ();// Put the Actioncontext in the threadlocal local thread                  request = prepare.wraprequest (Request),                 // The creation of Actionmapper mainly includes some request forwarding information, it will first go to the current request to find                  //if found, it is stored in the request domain and is created if not found. (Defaultactionmapper)                  actionmapping mapping = prepare.findactionmapping (request, response, true );                if  ( Mapping == null)  {                     boolean handled =  Execute.executestaticresourcerequest (Request, response);                     if  (!handled)  {  & Nbsp;                      chain.dofilter (Request, response);                     }                 } else {                 //If the filter does not have a square line after performing the action, So the struts filter can only be placed at the end of the                      execute.executeaction (request, response, mapping);//Perform action                  }             }        }  finally {             prepare.cleanuprequest (Request);         }                / /Create actioncontext          public actioncontext  Createactioncontext (Httpservletrequest request, httpservletresponse response)  {         ActionContext ctx;         Integer counter = 1;        Integer  oldcounter =  (Integer)  request.getattribute (cleanup_recursion_counter);         if  (oldcounter != null)  {             counter = oldCounter + 1;         }   &Nbsp;            actioncontext oldcontext  = actioncontext.getcontext ();//Get the original Actioncontext (if present)          if  (oldcontext != null)  {             //  Create a new ActionText and transfer the original context into the              ctx = new actioncontext (New hashmap<string, object> ( Oldcontext.getcontextmap ()));        } else {         //Create a valuestack         with Factory mode     valuestack stack = dispatcher.getcontainer (). GetInstance ( Valuestackfactory.class). Createvaluestack ();             //creates a Map collection (context) from the dispatcher and valuestack its methodContext to             //so there is a context index in the STATCK value stack             stack.getcontext (). PUTALL ( Dispatcher.createcontextmap (request, response, null, servletcontext));             ctx = new actioncontext (Stack.getContext ());         }         Request.setattribute (Cleanup_recursion_counter, counter);         Set Actioncontext        actioncontext.setcontext (CTX);         return ctx;    }         //Executive      Configuration config =  Configurationmanager.getconfiguration ();//Create a proxy object based on the configuration file             actionproxy proxy =  Config.getcontainer (). getinstance (Actionproxyfactory.class). Createactionproxy (                     namespace, name ,  method, extracontext, true, false);             request.setattribute (servletactioncontext.struts_valuestack_key,  Proxy.getinvocation (). Getstack ());             //  if the ActionMapping says to go straight to a result,  do it!            if  (Mapping.getResult ( )  != null)  {                 result result = mapping. GetResult ();//If the result is returned, the interceptor post-processing process is called recursively                  result.execute (Proxy.getinvocation ());             } else {                 proxy.execute ();//Call actioninvocation Call Interceptor              }


This article is from the "7317437" blog, please be sure to keep this source http://7327437.blog.51cto.com/7317437/1619509

STRUS2 Study Notes-process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.