简体   繁体   English

如何将JavaScript变量传递给struts2属性标签

[英]How to pass javascript variable to struts2 property tag

Here's my problem: 这是我的问题:

When I write this in javascript it works 当我用JavaScript编写此代码时

// 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. 但是,当我尝试在属性标签中动态设置该值时,没有任何执行。

// NOT OK: // 不好:

var value = 1000;

alert('<s:property value="@my.package.utils.Util@getSomeInformation(' + value + ')" />');

Can someone please help me in this? 有人可以帮我吗?

Struts Tags, like JSTL, EL, etc... are executed server side. Struts标签,例如JSTL,EL等,是在服务器端执行的。 After all of them are executed, the final page with HTML only is rendered to the client. 执行完所有这些步骤后,仅HTML的最终页面将呈现给客户端。 Only then, javascript can run on the page. 只有这样,JavaScript才能在页面上运行。

You can't mix javascript and Struts tags. 您不能混合使用javascript和Struts标签。

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. 另外,考虑不使用静态方法调用,您可以通过调用操作方法来执行此操作,并执行与Util.getSomeInformation方法相同的检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM