在struts-config.xml中,一个action里面有一个"attribute"属性。它是做什么的?

In struts-config.xml, an action has an "attribute" attribute in it. What's it do?

在我们的 web 应用程序的 struts-config.xml 文件中,定义了一堆 <action>,并且它们同时具有 nameattribute 属性他们中的大多数,两者都有表单名称。例如:

<action
    attribute="LoginForm"  <-- this line
    name="LoginForm"
    path="/welcome"
    type="com.foo.presentation.action.LandingActionPre">
    <forward name="SUCCESS" path="landing.welcome" />
    <forward name="ALREADY_LOGGED_IN" path="/landing.do?m=getLandingPage" redirect="true"/>
</action>

attribute 属性有什么作用?或者它没有被使用并且错误地出现在这里?

此应用程序已推出约 10 年,在此期间已有 40 多位程序员接触过代码库。因此,有可能有人将它添加到一些操作中,而其他人则在不知道更好的情况下将其复制并粘贴到应用程序的其余部分。

根据 Struts 1 doc type definition,它用作 ActionForm 的一种别名。

如果与name相同,则不执行任何操作。但是如果指定了 name 并且指定了 attribute 并且不同于 name,则可以使用 nameattribute 的值访问表单。

相关栏目:

<!-- The "action" element describes an ActionMapping object that is to be used
    to process a request for a specific module-relative URI. The following
    attributes are defined:

    attribute       Name of the request-scope or session-scope attribute that
                    is used to access our ActionForm bean, if it is other than
                    the bean's specified "name". Optional if "name" is specified,
                    else not valid.