Struts 2如何在值堆栈上引用具有动态名称的值
假设struts 2的valuestack中有一个值;当我们编写jsp代码时,我们不知道这个值的确切变量名是什么,但我们只知道这个值的变量名保存在另一个变量名中,比如“XXX”。
问题是如何使用“XXX”获取值,我尝试了这个,但它不起作用。
<s:property value="${XXX}"/>
Say there is a value in valuestack of struts 2; when we code the jsp, we don't know what the exact variable name of this value, but we only know that the variable name of this value is saved in another variable name, say "XXX".
The question is how can get the value by using "XXX", I try this, but it is not working.
<s:property value="${XXX}"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该操作为视图编组数据,因此它应该进行处理以获得所需的数据。从它的声音来看,听起来这个动作可以将适当的数据收集到地图中。
然而,也有一些奇怪的情况,你可能也遇到过。但在解决这个问题之前,如果您只有变量的名称,那么在哪里可以假设真正的变量在哪里?它是否在值堆栈中(如果是,是什么阻止您直接访问它)?如果它不在值堆栈上,则需要启用静态方法评估并创建适当的静态方法,因为仅向您提供变量的名称,并假设它是您需要的 java bean 的属性使用反射或 apache beanutils。
一般来说,最好在行动中获得你所需要的观点。
另外,要在 jsp 中设置一个值,您是否知道 struts2 set 标记(这可能不是您想要的,但有很小的可能,所以我将其包含在内)?请参阅: http://struts.apache.org/2.2.3.1/docs/set .html
The action marshals data for the view, as such it should do the processing to get the required data. From the sounds of it, it sounds like the action could gather the appropriate data into a map.
However there are strange cases and you might have one. But before addressing that if you only have the name of the variable where can it be assumed the real variable is? Is it in the value stack (and if so what is stopping you from accessing it directly)? If it is not on the value stack you'll need to enable static method assess and create an appropriate static method, since you are only provided with the name of the variable and assuming it is a property of a java bean you'll then need to use reflection or apache beanutils.
In general it is better to get what you need in the action for your views.
Also to set a value in your jsp's you are aware of the struts2 set tag (this is probably not what you want but there was a small chance it was so I included it)? See: http://struts.apache.org/2.2.3.1/docs/set.html