Struts2 OGNL call public static method details, struts2ognl
Struts2 OGNL calls public static methods
It has always been known that the OGNL of Struts2 supports calling static methods in the background at the front end. It has been used before, but is rarely used. Today, I started a new project, when a function is implemented, the static method of Struts2 is used to call the background method at the front end. After half a day, the result is not displayed, originally, I did not declare in the Struts configuration file that I could use the static method in the background at the front end, so I wrote it for my reference in the future and used it as a lesson.
Suppose there is a com. xxx. util. Util class, where there is a public static method called sayHello:
Public static String sayHello (String name) {return "HELLO" + name ;}
The static method can be called in the foreground as follows:
<: Property value = "@ com. xxx. util. Util @ sayHello ('tiantian ')"/>
To enable the frontend to call the public static method in the background smoothly, you must declare in the Struts configuration file that you can call the subsequent static method in the foreground.
<Constant name = "struts. ognl. allowStaticMethodAccess" value = "true"> </constant>
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!