Introduction to Structs2 Projection

Source: Internet
Author: User

First part: Code


Front
Accessing properties


Xml
<struts>
<constant name= "Struts.enable.DynamicMethodInvocation" value= "false" >
<constant name= "Struts.devmode" value= "true" >
<constant name= "Struts.ognl.allowStaticMethodAccess" value= "true" ></constant>
<include file= "/com/struts2/ognl/ognl.xml/" >
</include></constant></constant></struts>


Ognl.xml
<struts>
<package extends= "Struts-default" name= "OGNL" >

<result>/ognl.jsp</result>
</action>

<result type= "Chain" >ognl</result>
</action>
</package>
</struts>


Class Package
Ognl.java
Package COM.STRUTS2.OGNL;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import Java.util.HashSet;
Import java.util.List;
Import Java.util.Map;
Import Java.util.Set;
Import Com.opensymphony.xwork2.ActionSupport;
public class Ognlaction extends Actionsupport {
private String password;
Private String username;

private user user;
Private Cat cat;

Private list<user> users = new arraylist<user> ();
Private set<dog> dogs = new hashset<dog> ();
Private map<string, dog= "" > dogmap = new hashmap<string, dog= "" > ();


Public Ognlaction () {
Users.add (New User (1));
Users.add (New User (2));
Users.add (New User (3));


Dogs.add (New Dog (DOG1));
Dogs.add (New Dog (DOG2));
Dogs.add (New Dog (DOG3));

Dogmap.put (dog100, New Dog (dog100));
Dogmap.put (dog101, New Dog (dog101));
Dogmap.put (dog102, New Dog (dog102));
}


Public String execute () {
return SUCCESS;
}

Public String GetPassword () {
return password;
}

Public String GetUserName () {
return username;
}


Public User GetUser () {
return user;
}


Public Cat Getcat () {
return cat;
}

Public list<user> getusers () {
return users;
}
Public map<string, dog= "" > Getdogmap () {
return dogmap;
}


Public set<dog> Getdogs () {
return dogs;
}


Public String m () {
return hello;
}


public void Setcat (cat cat) {
This.cat = cat;
}

public void Setdogmap (map<string, dog= "" > Dogmap) {
This.dogmap = Dogmap;
}

public void Setdogs (set<dog> dogs) {
This.dogs = dogs;
}

public void SetPassword (String password) {
This.password = password;
}

public void SetUser (user user) {
This.user = user;
}

public void Setusername (String username) {
This.username = Username;
}

public void Setusers (list<user> users) {
This.users = users;
}
}

User.java
Package COM.STRUTS2.OGNL;
public class User {
private int age = 8;

Public User () {
}

Public User (int.) {
Super ();
This.age = age;
}




public int getage () {
return age;
}


public void Setage (int.) {
This.age = age;
}

@Override
Public String toString () {
return user + age;
}
}</user></dog></string,></dog></string,></user></string,></string ,></dog></dog></user></user>


Cat.java
Package COM.STRUTS2.OGNL;
public class Cat {
Private Dog friend;

Public Dog Getfriend () {
return friend;
}

public void Setfriend (Dog friend) {
This.friend = friend;
}

Public String Miaomiao () {
return Miaomiao;
}
}

Dog.java
Package COM.STRUTS2.OGNL;
public class Cat {
Private Dog friend;

Public Dog Getfriend () {
return friend;
}

public void Setfriend (Dog friend) {
This.friend = friend;
}

Public String Miaomiao () {
return Miaomiao;
}
}
?
1
Show
Access the normal properties of the action in the value stack: username =
Accessing the normal properties of an object in the value stack (Get Set method): | | | Wrong: <%----%>
Access the normal properties of the object in the value stack (Get Set method):
Common ways to access objects in the value stack:
Common ways to access objects in the value stack:
The normal way to access the action in the value stack:
To access a static method:
To access static properties:
To access the static methods of the Math class:
To access the normal class construction method:
Access list:
To access an element in the list:
Access a collection of attributes for an element in list:
To access a specific value in a collection of attributes for an element in list: |
Access Set:
To access an element in a set:
Access map:
To access an element in a map: | |
Access all keys in the map:
Access all the value in map:
Size of the Access container: |
Projection (filter):
Projection: 1}. {age}/>
Projection: 1}. {age}/>
Projection: 1}. {Age} = = Null/>
[]:
Part II: Analysis


After clicking, locate the file that contains it according to the configuration in the configuration file.
, find Ognl.xml file


<struts>
<package extends= "Struts-default" name= "OGNL" >

<result>/ognl.jsp</result>
</action>

<result type= "Chain" >ognl</result>
</action>
</package>
</struts>



Constructs the class object according to the class associated with the action in the XML configuration file;
The Ognl object is constructed according to Ognl.java;
Display stage to show the value, there are several ways to pay attention to:
Access value stack in the properties, the value stack of the object's methods, static methods, static properties, container objects;
Accessing the normal properties of an action in the value stack
Normal properties of objects in the value stack
Common methods for objects in the value stack
Common method of action in value stack
static method access method @ Class name @ Method name


Need to set value=true> in Web. xml
Ways to view the default settings:/struts2_1900_ognl/webroot/web-inf/lib/struts2-core-2.1.6.jar/default.properties
Accessing collections
Call method
?
1
Http://localhost:8080/Struts2_1900_OGNL/ognl.action?username=u&password=p&user.age = 19& Cat.friend.name =oudy
Part III: Discussion


Object Graph Navigation Language
Object Graph Navigation Language


Part IV: Discussion of projections


The projection is the filtering function.
Filter wording:
?
1

Projection (filter):
Projection: 1}. {age}/>
Projection: 1}. {age}/>
Projection: 1}. {Age} = = Null/>
To? ^ $ starts with filter conditions, and regular expressions are not the same;
This represents the object in the loop process and helps you to do some loops;


Projection (filter):
Represents the one from which the age=1 is removed from the users, and the result is a collection;


Projection (filter):
Represents the first one to remove age=1 from the users, and the result is one;
Projection: 1}. {age}/>
Represents the one from the end of the collection of age>1 removed from the users;

Introduction to Structs2 Projection

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.