6

我一直在为此寻找一个具体的答案,因为大部分谷歌都返回了很多非常古老的帖子。这是greetingActionForm在请求范围内,还是在会话范围内?action除了andform-bean声明之外还有其他位置可以确定表单的范围吗?

<action-mappings>
    <action path="/hello/my/oldfriend"
            type="com.imFine.HowAreYouAction"
            name="greetingActionForm"
            validate="true"
            input="/the/front/door">
        <forward name="success" path="/go/get/drinks.do" />
    </action>
</action-mappings>
<form-beans>
    <form-bean name="greetingActionForm" type="com.forms.GreetingActionForm"/>
</form-beans>
4

1 回答 1

10

如果未指定,默认情况下 ActionForm 将具有 scope session

ActionForm 的范围在<action>配置中指定为属性scope。您可以在 Struts DTD中找到它:

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:
     .....
     .....
     scope           The context ("request" or "session") that is used to
                     access our ActionForm bean, if any.  Optional if "name" is
                     specified, else not valid. [session]
     .....
     .....

该值在org.apache.struts.config.ActionConfig类中初始化,该类表示 Struts 模块配置文件中元素的配置信息:

/**
 * <p> Identifier of the scope ("request" or "session") within which our
 * form bean is accessed, if any. </p>
 */
protected String scope = "session";
于 2011-07-24T16:15:07.873 回答