Strut2 - 在下一个操作中获取属性值
我正在使用
我的 struts.xml 包含
<action name="someAction"
class="com.test.testaction.getValue"
method="getValuedemo">
<result name="success" type="redirectAction">demo</result>
</action>
而我的 Action 包含
public class getValue extends ActionSupport{
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getValuedemo() {
userName = "tmpUser";
}
}
我的问题是如何在 demo.action 中获取 userName 属性???请帮忙
I am using <s:form action="someAction">
my struts.xml contains
<action name="someAction"
class="com.test.testaction.getValue"
method="getValuedemo">
<result name="success" type="redirectAction">demo</result>
</action>
while my Action contains
public class getValue extends ActionSupport{
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getValuedemo() {
userName = "tmpUser";
}
}
My question is how to get userName property in demo.action????? Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将 userName 作为参数传递
也在演示操作中添加 userName getter/setter
You can pass userName as a parameter
Also add userName getter/setter in the demo action
与特定操作关联的值是针对每个请求的。如果您在操作中设置值然后重定向,这些值将会丢失。如果 getValue 只是重定向到演示,那么 getValue 操作的目的是什么?为什么不在 DemoAction 上只使用 userName getter 和 setter?
请修改您的问题以提供有关您正在尝试执行的操作的更多详细信息。
此外,您的操作名称不遵守类的 Java 命名约定,类应以大写字母开头。此外,您可能希望为该操作起一个比 GetValue 更好的名称。
Values associated with a specific action are per-request. If you set values in an action and then redirect, those values will be lost. If getValue is just redirecting to demo, what is the purpose of the getValue action? Why not just have the userName getter and setter on DemoAction?
Please revise your question to provide more details on what you are trying to do.
Additionally, your action name does not adhere to Java naming conventions for a class, which should start with a capital letter. Additionally, you might want to come up with a better name for the action than GetValue.
首先使用链结果类型...
然后阅读拦截器,这样您就可以避免使用链、重定向、redirectAction。
First use the chain result type...
Then read about interceptors so you can avoid using chain, redirect, redirectAction.