重定向到 Struts 2 中的默认操作
我有一个在根命名空间中定义名称为空字符串的操作,如果找到某个结果,我想从另一个操作重定向到该操作,但它似乎不起作用。
这是默认操作
<action name="" class="com.example.actions.HomeAction">
<result name="success" type="freemarker">freemarker/home.ftl</result>
</action>
,我正在包的全局结果中定义重定向:
<global-results>
<result name="sendToRouting" type="redirectAction">
<param name="actionName"></param>
<param name="namespace">/</param>
</result>
</global-results>
我尝试取出 actionName 参数,但这不起作用。如果我为 HomeAction 输入一个名称并在全局结果中按名称引用它,那么我假设问题是缺少重定向的操作名称。
有什么想法吗?
I have an action with an empty string for name defined in the root namespace, and I want to redirect to that action from another action if a certain result is found, but it doesn't seem to work.
Here's the default action
<action name="" class="com.example.actions.HomeAction">
<result name="success" type="freemarker">freemarker/home.ftl</result>
</action>
And I'm defining the redirect in the global-results for the package:
<global-results>
<result name="sendToRouting" type="redirectAction">
<param name="actionName"></param>
<param name="namespace">/</param>
</result>
</global-results>
I've tried taking out the actionName parameter, but that doesn't work. If I put a name in for the HomeAction and reference it by name in the global-results it works, so I'm assuming the problem is lack of action name for the redirect.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你想做的是使用
:抱歉...误读了问题:
尝试更改
type="redirectAction"
到type="redirect"
,我相当确定redirectAction现在是重定向。I think that what you want to do is use
<default-action-ref />
:Sorry...misread the question:
Try changing
type="redirectAction"
totype="redirect"
, I'm fairly sure that redirectAction is now redirect.您是否因为 actionName 参数为空而收到 NullPointerException?我通过提供一个评估为空字符串的字符串来解决这个问题:
尽管如此,仍在寻找更“正确”的解决方案......
Were you getting a NullPointerException because the actionName parameter is blank? I hacked around this by providing a string which evaluates to an empty string:
Still looking for a more "correct" solution though...