如何将javascript变量传递给struts2属性标记 [英] How to pass javascript variable to struts2 property tag
问题描述
这是我的问题:
当我在javascript中写这个时,它可以工作
When I write this in javascript it works
// OK:
alert('<s:property value="@my.package.utils.Util@getSomeInformation(1000)" />');
但是当我尝试在属性标记中动态设置该值时,没有执行任何操作。
But when I try to set that value dynamically in the property tag, nothing is being executed.
//不行:
var value = 1000;
alert('<s:property value="@my.package.utils.Util@getSomeInformation(' + value + ')" />');
有人可以帮我吗?
推荐答案
Struts标签,如JSTL,EL等......都是在服务器端执行的。执行完所有这些操作后,只有HTML的最终页面将呈现给客户端。只有这样,javascript才能在页面上运行。
Struts Tags, like JSTL, EL, etc... are executed server side. After all of them are executed, the final page with HTML only is rendered to the client. Only then, javascript can run on the page.
你不能混合使用javascript和Struts标签。
You can't mix javascript and Struts tags.
另外,考虑不使用静态方法调用,您可以通过调用action方法执行此操作,执行与 Util.getSomeInformation
方法相同的检查。
Also, consider not using static method calls, you can probably do this with a call to an action method, performing the same checks that Util.getSomeInformation
method does.
这篇关于如何将javascript变量传递给struts2属性标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!