本文共 1439 字,大约阅读时间需要 4 分钟。
1.OGNL静态访问例子
struts.xml:
IndexAction1.java:/ognl.jsp
package cn.edu.hpu.action;public class IndexAction1 { public String execute(){ return "success"; }}S.java
package cn.edu.hpu.ognl;public class S { public static String STR="STATIC STRING"; public static String s(){ return "static method"; }}链接:
访问静态方法:OGNL6访问静态属性:OGNL7结果界面:
访问Math类的静态方法:5
2.OGNL访问普通类的构造方法
struts.xml:
OgnlAction3.java:/ognl.jsp
package cn.edu.hpu.ognl;import cn.edu.hpu.mode.Dog;import com.opensymphony.xwork2.ActionSupport;public class OgnlAction3 extends ActionSupport{ private Dog dog; public Dog getDog() { return dog; } public void setDog(Dog dog) { this.dog = dog; } @Override public String execute() throws Exception { // TODO Auto-generated method stub return "success"; }}Dog.java:
package cn.edu.hpu.mode;public class Dog { private String name; public Dog(){ } public Dog(String name){ super(); this.name=name; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { // TODO Auto-generated method stub return "dog:"+name; }}链接:
访问普通类的构造方法:OGNL8结果页面:
转载请注明出处: