Struts ONGL, StrutsONGL
1. What is OGNL?
OGNL is the abbreviation of Object Graphic Navigation Language,
It is an open-source project. The Struts2 framework uses OGNL as the default expression language.
N times more powerful than EL.
OGNL is just an expression language. to use it, you must combine the Struts2 tag.
Measure the test taker's knowledge about the value stack and the Struts2 core.
2. The value stack is a lightweight memory data center corresponding to each request object.
(Save all data related to a request to the ValueStack object ).
(1). ValueStack is actually an interface. When using OGNL in Struts2, it actually uses the OgnlValueStack class that implements this interface. This class is the basis for Struts2 to use OGNL.
(2). ValueStack throughout the lifecycle of an Action: each Action class instance has a ValueStack object. ValueStack is equivalent to a data transfer station. It stores information about the current Action object and other related objects.
(3). The Struts2 framework stores the ValueStack object in the request attribute "struts. valueStack.
Request. setAttribute ("struts. valueStack", );
3. ValueStack Internal Structure
ValueStack stores two attributes:
1. root: root, type CompoundRoot, whose essence is ArrayList.
2. context: context. The type is Map.
The structure is as follows:
How to access data in ValueStack:
<S: property value = ""/>
If the data in the root user is accessed, access the data directly. <s: property value = "property name"/>
If the data in the context is accessed, use. # <s: property value = "# attribute name"/>.
4. How to obtain the value stack object
Method 1:
ValueStack vs = (ValueStack) requets. getAttribute ("struts. valueStack ");
Method 2:
ValueStack vs = ActionContext. getContext (). getValueStack ();
5. Four Methods for saving data to the value stack (mainly for root objects:
① Save the data to the root index 0 position and place it to the first element ArrayList. add (0, element );
ValueStack. push ("one leaf and one boat"); Data pressure Stack
②. Create a parameter map in the value stack and save the data to the map.
ValueStack. set ("age", "22 ");
In general, as long as we provide the attribute access method (getXxx) in the Action class, it will be automatically pressed to the top of the stack.
Class xxAction {}
Private User user;
// Attribute user
Public User getUser (){
Return user;
}
}
<S: property value = "user. name"/>
<S: property value = "user. age"/>
Struts2 supports the use of EL expressions to obtain information. Strutss rewrites the code for EL to obtain attributes.
6. Save data to the value stack (mainly for contextt objects) in two ways:
ActionContext. getContext (). getContextMap (). put ("name", "");
// SIMPLE METHOD
ActionContext. getContext (). put ("name", "No regrets ");
Application of ValueStack in development
Mainstream applications: Value stack solves the problem of data transfer from Action to JSP
Action transmits data processing results to JSP. There are two forms of result data:
1) message String type data
Super. addFieldError ("msg", "field error message ");
Super. addActionError ("Action Global error message ");
Super. addActionMessage ("message of Action ");
FieldError indicates a field error message (often used for Form Verification ),
ActionError (common error message, failed to log on to a field ),
ActionMessage common message
Use struts2 in jsp to provide tag Display message information
<S: fielderror fieldName = "msg"/>
<S: actionerror/>
<S: actionmessage/>
2) data (complex data types)
<S: iterator/> label
If the data is stored in root:
Public List <User> getList (){
Return list;
}
<S: iterator value = "list">
<S: property value = "name"/> <s: property value = "email"/> <s: property value = "age"/> <br/>
</S: iterator>
During iteration, each iteration object is pushed to the top of the stack.
If the data is stored in context:
ActionContext. getContext (). put ("userList", list );
<S: iterator value = "# userList">
<S: property value = "name"/> <s: property value = "email"/> <s: property value = "age"/> <br/>
</S: iterator>
For struts2 ongl
First, the title is wrong. It is OGNL.
You have used the convenient object structured view here.
You need to provide encapsulation of the one attribute in first
As you said, if the form is submitted, it is assigned a value.
Ask a struts2 ongl question,
Haha
You think this is wrong.
Because he doesn't know that you only have one.
It is a collection type ..
No, I won't judge your size.
Treated as a collection