我一直在寻找一个具体的答案,因为很多谷歌都会回复很多很老的帖子。这是greetingActionForm
在请求范围内还是在会话范围内?是否有action
和form-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>
答案 0 :(得分:9)
如果未指定,默认情况下,ActionForm的范围为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";