struts2 的标签里如何访问一个类的静态方法或属性?
比如有一个单态模式的类:
Java code
package stu.struts2.tags;
public class SingleObject {
private static SingleObject instance = new SingleObject();
public static SingleObject getInstance(){
return instance;
}
public java.util.List<Person> getPersonList(){
// Person 是另外定义的具有一些 getter 和 setter 的类
java.util.List<Person> result = new java.util.ArrayList<Person>();
result.add("aaa");
result.add("bbb");
return result;
}
public static String getName(){
return "test";
}
public static SingleObject getInstance(){
return instance;
}
private SingleObject(){
}
}
而在下面的jsp中 property 标签并没有输出任何内容(而我其实是想在jsp中遍历SingleObject.getPersonList()返回的列表):
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:property value="@stu.struts2.tags.SingleObject@Name"/><hr/>
<s:property value="@stu.struts2.tags.SingleObject@getName"/><hr/>
<s:property value="@stu.struts2.tags.SingleObject@getName()"/>
</body>
</html>
------解决方案--------------------
------解决方案--------------------
struts.xml中添加
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />