Use Struts2 --- OGNL expression and the value of the stack

1.OGNL expression

OGNL usage

      <% @ Taglib uri = "/ struts-tags" prefix = "s"%> Import tab
      

      

OGNL special characters #% $

      # Usage: # may be used to obtain the value of the object field, it can also be used to define a map
                     

      % Usage: forced resolves to OGNL expression (or forced not resolving OGNL expression), the label can only be used in OGNL
                    

      $ Usage:

2. The value of the stack

    When an action is created from time to time, and it will create a serve of ValueStack

  The value of the internal structure of the stack

      root area --CompoundRoot ---- in fact, an ArrayList    
         put some objects

      --OgnlContext ---- regional context is actually a Map
         to put some common web development application objects, such as request, session, application

  Get the value stack objects

      Two ways

@Override
	public String execute() throws Exception { //获得值栈对象方式一 ValueStack stack1 = ActionContext.getContext().getValueStack(); //获得值栈对象方式 二 ServletActionContext.STRUTS_VALUESTACK_KEY==struts.valueStack ValueStack stack2 = (ValueStack) ServletActionContext.getRequest().getAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY); //两种方法获得的值栈对象是同一个 System.out.println(stack1==stack2);//ture return SUCCESS; }

  Stack operation target value - the value of the data stored in the root stack

      1. provided in the action attribute get method can be stored, as they can, through page <s: property value = "user.username " /> obtain a user name
        

      2. push or set the data into the stack, the method generates a set map object, and places it in the stack
 

Guess you like

Origin www.cnblogs.com/zy-Luo/p/11033151.html