OGNL语法问题 [英] OGNL Syntax Issue

查看:136
本文介绍了OGNL语法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下代码段的Struts 2 JSP页面:

I have a Struts 2 JSP page with the following snippet:

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

正确打印出 myVariable 的值。

现在,我想将 myVariable 传递给我的行动中的方法,该方法根据值计算结果 myVariable 。我尝试了以下方法:

Now, I want to pass myVariable to a method in my action that computes a result based on the value of myVariable. I tried the following:

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

myMethod 中的第一行打印出来调试声明。使用上面的代码片段,这个调试语句没有打印出来。

The first line in myMethod prints out a debug statement. With the above snippet, this debug statement was not printed.

然后我尝试了这个:

<s:property value="%{myMethod(#myVariable)}" />

我的调试语句已打印,但 myVariable的值被传递为null,即使它在通过< s:property value =%{myVariable}/>

My debug statement printed, but the value of myVariable was passed as null even though it has a value when it is printed via <s:property value="%{myVariable}" />

将页面变量传递给Struts 2方法的正确语法是什么?

What is the correct syntax for passing a page variable to a Struts 2 method?

推荐答案

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

是正确的语法,但要获取具有签名的方法的值

is a correct syntax, but to get the value of the method that have a signature

public String myMethod(String value){
  return value;
}

需要 myVariable的吸气剂

public String getMyVariable() {
  return myVariable;
}

如果将值设置为 myVariable 喜欢

private String myVariable = "myValue";

然后它应该在JSP中打印。如果参数是其他类型,它将转换为 String ,并且该方法将调用。

then it should be printed in JSP. If the argument is other type it will be converted to String and the method will call.

这篇关于OGNL语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆