質問

How to call an action method using OGNL?

helloAction.java

public String getQuote()
{
    return "Don't think, just do";
}

success.jsp

<b>quote() :</b> <s:property value="quote()"/> <br>

struts.xml

<action name="greet" class="com.struts2.helloAction" >
    <interceptor-ref name="firewallStack"></interceptor-ref>
    <result name="SUCCESS">/WEB-INF/resources/success.jsp</result>
    <result name="input">/WEB-INF/resources/success.jsp</result>
</action>

I got the ref link from struts 2 OGNL

This quote() method is not called. I am using xwork-2.0.1.jar and ognl-2.6.11.jar.

役に立ちましたか?

解決 2

This quote() method is not called. I am using xwork-2.0.1.jar and ognl-2.6.11.jar.

You don't have that method in your action. If you create it:

public String quote() {

and use normal OGNL method call syntax:

<s:property value="%{quote()}" />

then it will be called as desired.

For details information and syntax you can read OGNL Language Guide.

他のヒント

Your original syntax is almost correct–just leave off the parens.

<s:property value="%{quote}" />

JavaBean contentions are more general-purpose than explicit method invocation, e.g., use JSP EL:

${quote}

JavaBean conventions are be preferred when the function takes no arguments.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top