struts url标签传递参数的问题
<display:column property="id" sortable="true"
paramId="id" paramProperty="id" titleKey="adminList.id"/>
<display:column property="username" sortable="true" titleKey="adminList.username"/>
<display:column property="password" sortable="true" titleKey="adminList.password"/>
<display:column>
<s:url id="removeUrl" action="remove">
<s:param name="id" value="37" />
</s:url>
<s:a href="%{removeUrl}" theme="ajax" targets="adminList">Remove</s:a>
</display:column>
</display:table>
当我执行这段代码时,该语句
<s:param name="id" value="37" />
将被完美执行,但我无法在 struts 操作类中获得该值。 另外,如果我通过了
<s:param name="id" value="adminList.id" />
,那么什么也不会通过
<display:column property="id" sortable="true"
paramId="id" paramProperty="id" titleKey="adminList.id"/>
<display:column property="username" sortable="true" titleKey="adminList.username"/>
<display:column property="password" sortable="true" titleKey="adminList.password"/>
<display:column>
<s:url id="removeUrl" action="remove">
<s:param name="id" value="37" />
</s:url>
<s:a href="%{removeUrl}" theme="ajax" targets="adminList">Remove</s:a>
</display:column>
</display:table>
when i will execute this code the statement
<s:param name="id" value="37" />
will be excecuted perfectly but I can't get that value in struts action class.
also if i pass
<s:param name="id" value="adminList.id" />
then it will pass nothing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很难确切地说出了什么问题,但我可以猜测:
如果您没有在 struts 操作中获取值,请检查您是否有一个名为 id 的属性以及操作类中定义的 gettId() 和 settId() 方法。 Struts 将尝试按名称填充参数中的所有属性。 您正在传递一个名为 id 的参数。
问题的第二部分是您没有正确访问变量。 试试这个:
假设 adminList 是对象的名称而不是集合的名称?
Its hard to say exactly what is wrong but I could guess:
If you are not getting the value in the struts action then check that you have a property called id along with the gettId() and settId() methods defined in the action class. Struts will attempt to populate all the properties from the parameters by name. You are passing a parameter named id.
The second part of the problem is that you are not accessing the variable properly. Try this:
assuming that adminList is the name of the object and not the name of your collection?
adminlist 是一个实际的对象或集合(我只是查看名称来做出该假设)。 检查 adminList 是否确实在 ValueStack 上,尝试打印
如果您没有看到它,则说明您还没有完成放置的工作它在值堆栈上。 但假设 id 对象的实际名称是 id,例如 int id; 并且该 id 对象具有适当的 getter,public int getId(); 那么它应该可以正常工作。Is adminlist an actual object or collections (I am just looking at the name to make that assumption). Check to see the adminList is actually on the ValueStack, try printing out
<s:property value="%{adminList}"/>
If you do not see it you havent done the work to place it on the value stack. But assuming the actual name of the id object is id, such like int id; and that id object has the appropriate getter, public int getId(); Then it should work fine.