In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about the analysis of Struts2 OGNL, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.
Enhancement based on Struts2 OGNL
1. Value stack (ValueStack)
The Struts2 OGNL context is set to ActionContext in Struts2 (OgnlContext is still used internally), and the value stack is set to the root object of Struts2 OGNL.
We know that the root object in the Struts2 OGNL context can be accessed directly without using any special "tag", while other objects in the reference context need to be marked with "#". Because the value stack is the root object in the context, it can be accessed directly. So how do you access the objects in the value stack? Struts2 provides a special OGNLPropertyAccessor that automatically finds all the objects in the stack (from the top of the stack to the bottom of the stack) and directly finds an object with the attributes you are looking for. That is, any object in the value stack can be accessed directly without using "#".
Suppose there are two objects in the value stack: student and employee, both of which have the name attribute, student has the student number attribute number, and employee has the salary attribute salary. Employee enters the stack first, then student, which is at the top of the stack, so for the expression name, you access the name property of student, because the student object is at the top of the stack; the expression salary accesses the salary property of employee. As you can see, accessing object properties or methods in the value stack does not specify an object or "#", as if the objects in the value stack are root objects in the context of OGNL. This is the improvement made by Struts2 based on OGNL.
2. [n] grammar
As mentioned above, how do I write an expression if I want to access the name property of employee? We can use syntax such as [N] .xxx (N is an integer starting at 0) to specify where to look down for the object's properties, and the expression [1] .name accesses the name property of the employee object.
When using the [N] .xxx syntax, pay attention to the meaning of the position sequence number, which does not mean to "get the object in the stack with index N", but to intercept part of the stack starting at position N.
3. Top keyword
Top is used to get objects at the top of the stack, and combined with [N] .xxx syntax, we can get objects anywhere on the stack.
Such as: [0] .top, [1] .top, etc.
4. Access static members
In addition to using standard OGNL expressions to access static fields and static methods, Struts2 also allows you to call static fields and static methods stored in the stack through the "vs" prefix instead of specifying the full class name.
@ vs@FOO_PROPERTY@vs@someMethod () @ vs1@someMethod ()
Vs stands for ValueStack, and if there is only vs, the class of the object at the top of the stack will be used; if vs is followed by a number, the object class at the specified location in the stack will be used.
Standard method: @ class fully qualified name @ static property or method name
< ?xml:namespace prefix = s /> < s:property value="@action.SystemInfo@WEB_CONTEXT"> < /s:property>5. Action instance in the value stack
The Struts2 framework always puts Action instances on top of the stack. Because Action is in the value stack, and the value stack is the root of OGNL, the attribute referencing Action can omit the "#" tag, which is why we can access the property of Action directly in the result page.
6. Named objects in Struts2
Struts2 also provides named objects that are not stored in the value stack but in ActionContext, so access to these objects requires the use of the "#" flag. These named objects are of type Map.
Parameters
Used to access request parameters. For example, # parameters ['id'] or # parameters.id is equivalent to calling the getParameter () method of the HttpServletRequest object.
Note that parameters is essentially a Map object constructed using the request parameters in the HttpServletRequest object, and once the quantity object is created (before the Action instance is called), it has nothing to do with the HttpServletRequest object.
Request
Used to access request properties. For example, # request ['user'] or # request.user is equivalent to calling the getAttribute () method of the HttpServletRequest object.
Session
Used to access the session property. For example, # session ['user'] or # session.user is equivalent to calling the getAttribute () method of the HttpSession object.
Application
Used to access the application property. For example, # application ['user'] or # application.user is equivalent to calling the getAttribute () method of ServletContext.
Attr
If PageContext is available, visit PageContext, otherwise search for request, session, and application objects in turn.
After reading the above, do you have any further understanding of the analysis of Struts2 OGNL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.