Struts2 OGNL call public static method details, struts2ognl

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.