简体   繁体   English

如何在JSP的Java函数中将Struts2属性标记作为参数传递?

[英]How to pass Struts2 property tag as parameter in java function in the jsp?

I am having a problem in passing Struts2 property tag as parameter in java function in the jsp. 我在将Struts2属性标记作为jsp的java函数中的参数传递时遇到问题。 I am calling a java function like this from jsp, 我正在从jsp调用这样的Java函数,

<s:if test="%{DoSomething()}">

DoSomething() function is in the Action class, and is being called for each record in the iterator. DoSomething()函数在Action类中,并且为迭代器中的每个记录调用。

The problem is that I want to pass this property <s:property value="userId"/> in the function DoSomething as java string as follow. 问题是我想在函数DoSomething将此属性<s:property value="userId"/>传递为java字符串,如下所示。

<s:if test="%{DoSomething("<s:property value="userId">/)}">

Can anyone please guide me that how can I do that. 谁能指导我该怎么做。 I goggled it but did not find anything. 我瞥了一眼,但是什么也没找到。

<s:if test="%{DoSomething(userId)}">

您不能将Struts2标记用于另一个Struts2标记,可以使用表达式语言,首先使用<s:set name="userId" value="userId" />然后使用${userId}

Most likely you wouldn't need to pass in a parameter like this. 最有可能您不需要传递这样的参数。 You are trying to call a method DoSomething from your action class. 您正在尝试从操作类中调用DoSomething方法。 You want to pass in a parameter to this method in your action class. 您想在操作类中将参数传递给此方法。 The userId must be existing already in you action class otherwise you couldn't be able to get it through the s:property tag. 该userId必须已经存在于您的操作类中,否则您将无法通过s:property标记获取它。 You can just use this userId variable in your DoSomething method of your action class. 您只能在操作类的DoSomething方法中使用此userId变量。

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

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