For Static Method Access, you must need to add following constant in your
struts.xml
file.<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
Example: struts.xml:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
<package name="default" namespace="/" extends="struts-default">
<action name="sampleAction" class="vaannila.SampleAction">
<result name="success">/WEB-INF/JSP/sample.jsp</result>
</action>
</package>
</struts>
Then from your JSP you can access it in various ways:
Example - 1:
<b>Output :</b> <s:property value="@vaannila.SampleAction@getSTR()"/> <br>
Where,
vaannila
= Package Name.SampleAction
= Class Name.getSTR()
= Method Name.
Example - 2:
<b>Output :</b> <s:property value="@vs@getSTR()"/> <br>
Where,
vs
= Value Stack.getSTR()
= Method Name.
Example - 3:
<b>Output :</b> <s:property value="%{STR}"/> <br>
where,
STR
=STR
is declared and initialized as Static String with getter and setter method in your Java Class
No comments:
Post a Comment