1.静态的方法调用:将同一个逻辑单元的多个功能定制在同一个Action中
class UserAction extends ActionSupport{
public String execute(){

}
public String queryEmp(){
xxx
}
public String removeEmp(){
xxx
}
public String updateEmp(){
xxx
}
public String insertEmp(){
xxx
}
}
struts.xml:
<action name="query" class="com.xxx.UserAction">
.......
</action>
​​​ http://localhost:8989/appname/namespace/queryEmp35​​​ <action name="queryEmp35" class="com.xxx.UserAction" method="queryEmp">
.....
</action>
http://localhost:8989/appname/namespace/removeEmp35
<action name="removeEmp35" class="com.xxx.UserAction" method="removeEmp">
.....
</action>
*注意:配置中的method="Action类中定义的方法名"
================================================================================================
2.动态方法调用
class UserAction extends ActionSupport{
public String query1(){

}
public String query2(){

}
public String query3(){

}
}
struts.xml
http://localhost:8989/appname/namespace/abc
<!--
name="c35_*":中的* 是通配符,可以匹配任意多个任意字符,则此Action可以同/c35_xx访问
:当用【/c35_query】访问此Action时,则*匹配到的字符是【query】,则method="query",则执行query方法
:当用【/c35_delete】访问此Action时,则*匹配到的字符是【delete】,则method="delete",则执行delete方法
:当用【/c35_update】访问此Action时,则*匹配到的字符是【update】,则method="updaet",则执行update方法
:当用【/c35_insert】访问此Action时,则*匹配到的字符是【insert】,则method="insert",则执行insert方法
【/c35_queryAll】
method="{1}":中的{1} 占位符,在此位置上的值,由每次请求中*所匹配到的字符来填充
则:
url:http://localhost:8989/appname/dmi/c35_query35 访问query35方法
url:http://localhost:8989/appname/dmi/c35_remove35 访问remove35方法
-->
<action name="c35_*" class="xxx" method="{1}">
...
</action>


*细节:
1.表单访问:
<form action="/appname/c35_query35">

</form>
2.跨包访问:
<package name="x" extends="xx" namespace="/a">
<action name="c36_*" class="xxx" method="{1}">
<result name="ok" type="redirectAction">
<param name="namespace">/b</param>
<param name="actionName">c35_query35</param>
</result>
</action>
</package>
<package name="xx" extends="xx" namespace="/b">
<action name="c35_*" class="xxx" method="{1}">
...
</action>
</package>
=============================================================================================
3.struts2数据处理机制
数据存储:作用域 作用域+值栈
数据获取:EL ${} OGNL表达式
数据展示:<c:forEach ... <s:
=============================================================================================
4.OGNL:(Object graphic navigation language 对象图导航语言)取值语言
独立第三发组件,用于取值。
取值特点:取值来源于-->[上下文,根对象]
*上下文(context):Map
*根对象(root):java对象
*OGNL 取值语法:
1>从根对象中取值:
*可以通过【属性名】即可获取属性值
Integer age=(Integer)Ognl.getValue("age",new HashMap(),user);
*当取出的值是一个对象时,可以通过【.属性名】获取其对应属性值
String city=(String)Ognl.getValue("addr.city",new HashMap(),user);
*当取出的值是一个数组或List,可以通过【[index]】获取对应索引位置的元素
Integer id=(Integer)Ognl.getValue("addrs[2].id",new HashMap(),user);
*当取出的值是一个Map时,可以通过【.key】获取对应的value
Integer id=(Integer)Ognl.getValue("addrMap.addr1.id",new HashMap(),user);
2>从上下文取值:*注意,从上下文中取值,ognl表达式要以#开头
*可以通过【#key】获取对应的value
Integer id=(Integer)Ognl.getValue("#id",map,new Object());
*当取出的值是一个对象,可以通过【.属性名】获取属性值
Integer id=(Integer)Ognl.getValue("#addr35.id",map,new Object());
*当取出的值是一个数组或List,可以通过【[index]】获取对应索引位置的元素
Integer id=(Integer)Ognl.getValue("#addrs[1].id",map,new Object());
*当取出的值是一个Map,可以通过【.key】获取对应的value
String ho=(String)Ognl.getValue("#hobby.sunzhen",map,new Object());
*ognl细节:
1>在通过ognl取值后,可以调用返回值对应类型中的所有公开方法
Char a=(Char)Ognl.getValue("#addr35.city.charAt(1)",map,new Object());
Integer size=(Integer)Ognl.getValue("addrs.size()",new HashMap(),user);
2>赋值
User user=new User();
Ognl.setValue("age",new HashMap(),user,19);
3>运算:
算术运算:+ - * / %
比较运算:> < == != >= <=
逻辑运算:&& || !
Map map =TestOgnl.getMap();
System.out.println(Ognl.getValue("(!((#id+2)>102))&&(#id>100)",map,new Object()));
=============================================================================================