1 . <s:property value="username"/>,可以直接取出value stack中的值。
需要注意的是:这里传递的参数的名称必须与Action类中该参数对应的set方法的名称一致。
2 . (domainModel)xxxAction.java 中有User对象的属性时,要给Use传值才能初始 化。
注意,User中一定要有参数为空的构造方法,除非在Action中直接new一个User对象。
3 . 访问Math类的静态方法 <s:property value="@@max(4,5)"/> 这种方式只能访问Math类的。
访问静态方法 <s:property value="@com.demo.ognl.S@s()"/>
访问静态属性 <s:property value="@com.demo.ognl.S@STR"/>
package com.demo.ognl;
public class S {
public static String STR = "static param";
public static String s() {
return "static method";
}
}
要访问静态方法 需要在struts.xml中配 置:
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>