简体   繁体   English

为什么我不能将一个动作重定向到Struts2中的另一个动作?

[英]Why can't i redirect an action to another action in Struts2?

i am using Struts2. 我正在使用Struts2。 I have a dialog box with a list of persons that is update through the "search_users" action. 我有一个对话框,其中包含通过“search_users”操作更新的人员列表。 Next to this list i have a form that you can use to add another person by calling the "add_user" action when the form is submitted. 在此列表旁边,我有一个表单,您可以在提交表单时通过调用“add_user”操作来添加另一个人。

What i'm trying to do is that, once the add_user action is performed, the list gets updated using the "search_user" action. 我要做的是,一旦执行了add_user操作,就会使用“search_user”操作更新列表。

I tried using the result type "redirect" in the struts.xml like this: 我尝试在struts.xml中使用结果类型“redirect”,如下所示:

<action name="search_users" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLSubequipo" method="searchUsers">
            <result name="success">list.jsp</result>
        </action>

        <action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
            <result name="success" type="redirectAction">search_users</result>
        </action>

But that doesn't work. 但这不起作用。 What am i doing wrong? 我究竟做错了什么? Is there something i should add to the struts.xml file that i'm not aware of? 有什么东西我应该添加到我不知道的struts.xml文件中吗?

This is the error mesage i get: 这是我得到的错误消息:

"Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success'.  Did you mean 'redirectAction'? - result - file:/.../struts.xml:59:44
    at ..."

Current Configuration: 当前配置:

<action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
   <result name="success" type="redirectAction">search_users</result>
</action>

As per the documentation correct format is: 根据文档正确的格式是:

<action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
    <result type="redirectAction">
        <param name="actionName">search_users</param>
        <!--<param name="namespace">/secure</param> This is optional if your action where you are redirecting is in the same namespace you can leave this, if your action is in some other name space then provide the namespace--> 
    </result>
</action>

Currently using Struts 2.3.20 , this works: 目前使用Struts 2.3.20 ,这有效:

<result type="redirectAction">myAction</result>

I have not confirmed in prior versions. 我在之前的版本中没有确认。

I'm not a big Struts guy but based on the documentation it looks like your redirect is not syntactically correct: http://struts.apache.org/2.1.6/docs/redirect-action-result.html 我不是一个伟大的Struts家伙,但基于文档看起来你的重定向在语法上是不正确的: http//struts.apache.org/2.1.6/docs/redirect-action-result.html

<package name="public" extends="struts-default">
    <action name="login" class="...">
        <!-- Redirect to another namespace -->
        <result type="redirect-action">
            <param name="actionName">dashboard</param>
            <param name="namespace">/secure</param>
        </result>
    </action>
</package>

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

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