重定向到 Struts 2 中的默认操作 [英] Redirect to default action in Struts 2
问题描述
我有一个在根命名空间中定义的名称为空字符串的操作,如果找到某个结果,我想从另一个操作重定向到该操作,但它似乎不起作用.
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.
这是默认操作
<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>
我试过去掉 actionName 参数,但这不起作用.如果我为 HomeAction 输入一个名称并在它的全局结果中按名称引用它,那么我假设问题是缺少重定向的操作名称.
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.
有什么想法吗?
推荐答案
我认为你想做的是使用
:
I think that what you want to do is use <default-action-ref />
:
<package name="home" namespace="/" extends="struts-default">
<default-action-ref name="home" />
<action name="home" class="com.example.actions.HomeAction">
<result name="success" type="freemarker">freemarker/home.ftl</result>
</action>
</package>
抱歉...误读了问题:
Sorry...misread the question:
尝试将 type="redirectAction"
更改为 type="redirect"
,我相当确定 redirectAction 现在是重定向.
Try changing type="redirectAction"
to type="redirect"
, I'm fairly sure that redirectAction is now redirect.
这篇关于重定向到 Struts 2 中的默认操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!