惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
SecWiki News
SecWiki News
Project Zero
Project Zero
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
A
Arctic Wolf
Security Latest
Security Latest
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
The Hacker News
The Hacker News
T
Tenable Blog
雷峰网
雷峰网
有赞技术团队
有赞技术团队
V
V2EX
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threat Research - Cisco Blogs
T
Threatpost
AWS News Blog
AWS News Blog
L
LINUX DO - 热门话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
SegmentFault 最新的问题
月光博客
月光博客
Spread Privacy
Spread Privacy
S
Secure Thoughts
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
Forbes - Security
Forbes - Security
T
The Exploit Database - CXSecurity.com
G
GRAHAM CLULEY
The Last Watchdog
The Last Watchdog
Y
Y Combinator Blog
I
Intezer
博客园 - 【当耐特】
B
Blog RSS Feed
Attack and Defense Labs
Attack and Defense Labs
I
InfoQ
博客园 - 叶小钗
Cyberwarzone
Cyberwarzone
V2EX - 技术
V2EX - 技术
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
H
Help Net Security
C
CERT Recently Published Vulnerability Notes

博客园 - 锐

Windows7 Server 2008 下安装Oracle 10g提示“程序异常终止,发生未知错误”的解决方法 Android应用自动更新功能的代码实现 Undefined exploded archive location 项目不能部署 linux下mysql5.5.19编译安装笔记【已验证】 CSS+DIV排版时容器内对象全部设置了float属性后容器不能自动适应高度的解决方案 php Smarty模板生成html文档的方法 - 锐 - 博客园 如何解决Firefox检测不到div高度问题 DD_belatedPNG,解决IE6不支持PNG绝佳方案 .net程序运行在无.net framework环境中 简体-繁体互转换的一个JS - 锐 - 博客园 C#实现通过URL触发自己的程序 Tencent://Message/协议的实现原理 - 锐 - 博客园 国内三大免费流媒体WAP门户网站(视频类WAP网站) C#中RSA加密解密和签名与验证的实现 (转) C#读取CPUid,硬盘id,网卡Mac地址 Struts2.1.6使用小技巧 java -D参数简化加入多个jar MySQL Proxy 学习笔记(转) 用apache ab做web压力测试
struts2 freemarker当中引进java 常量java静态方法 - 锐
· 2010-10-18 · via 博客园 - 锐

1.首先在struts.sml中配置<constant name="struts.ognl.allowStaticMethodAccess" value="true" />

表示允许使用静态java方法。非常重要。

2.在freemarker中引进java常量的方法:

假如:

Test.java

package test;

public class Test{

private String userSex=MAN;

public static final String MAN="男";

public static final String WOMAN="女";

public static String m()
{

return "test";
}

public String getUserSex()
{
return userSex;
}

public void setUserSex(String userSex)
{
this.userSex = userSex;
}

}

接下来我们在freemarker中调用该类中的 静态常量 和静态方法

a.调用常量:

${stack.findValue("@com.wish.maml.freemarkerexample.model.User1@MAN")}
</br>
${stack.findValue("@com.wish.maml.freemarkerexample.model.User1@m()")}

就会出现想要的结果

注意:目前只是调用静态的

补充:这里目前调用方法必须有返回值不能为void方法,如果是static void方法,那么运行页面的时候会走这个方法,但是没有值,所以会出错,这时候最好用个

${stack.findValue("@com.wish.maml.freemarkerexample2.freemarkerexample2.S@haha('aaa')")!"no"}

判断不存在的时候 显示 no

附带源代码如下

java

public class S
{
public static String str = "nih";

private String name = "";

public static String say()
{
return "good";
}

public static void haha(String ha)
{
System.out.println(ha);
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}

public static S getS()
{
S s = new S();
s.setName("中国");
return s;
}
}

ftl:

${stack.findValue("@com.wish.maml.freemarkerexample2.freemarkerexample2.S@str")}
${stack.findValue("@com.wish.maml.freemarkerexample2.freemarkerexample2.S@say()")}
${stack.findValue("@com.wish.maml.freemarkerexample2.freemarkerexample2.S@haha('aaa')")!"no"}

${stack.findValue("@com.wish.maml.freemarkerexample2.freemarkerexample2.S@getS().name")!"no"}