Struts2 ActionContext and ValueStack?

My questions:

  • In Struts2, each action object has its own ActionContext and ValueStack?

In other words, a new action object is created for each new request. Does this mean that every time a new action object is created, a new ActionContext and ValueStack are also created?

  1. Consider this scenario:

Action1 ------ 1st req -------> view.jsp ------ 2nd req ---------> action2.

So, when the request comes for action1, a new action1 object is created and the corresponding ActionContext and ValueStack.

From view.jsp (when clicking the hyperlink) a new request appears for action2.

Does this mean that previous ActionContext and ValueStack (associated with action1) are destroyed and new ActionContext and ValueStack (for action2) are created?

  1. Suppose I store something in ActionContext (of action1) in view.jsp and then click on the hyperlink for action2 (from view.jsp), will this data be lost along with ActionContext (of1)?
+3
source share
2 answers
  • Yes
  • Yes, after the completion of the action will be performed.

    //SourceCode from StrutsPrepareAndExecuteFilter.
    
    //Cleans up a request of thread locals
    
    public void cleanupRequest(HttpServletRequest request) {
    
      Integer counterVal = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
      if (counterVal != null) {
          counterVal -= 1;
          request.setAttribute(CLEANUP_RECURSION_COUNTER, counterVal);
          if (counterVal > 0 ) {
              if (log.isDebugEnabled()) {
                  log.debug("skipping cleanup counter="+counterVal);
              }
              return;
          }
      }
    
      // always clean up the thread request, even if an action hasn't been executed
      ActionContext.setContext(null);
      Dispatcher.setInstance(null);
    }
    

3. Yes, if you want this data to be available in the chain of use of the next action (not recommended).

+1
source

Q1. There is one ActionContext, and there is only one ValueStack.

Q2.

Does this mean that the previous ActionContext and ValueStack (associated with action1), and a new ActionContext and ValueStack (for action2) are being created?

No.

Q3. . , ThreadLocal, ActionContext, , , ValueStack .

+1

All Articles