1、在一般情况下,actionForm是被存储在一定的scope中(request或session,通过action的scope属性来配置),当我们在配置时,指定name而不指定attribute,那么指定的name值就作为actionForm存储在scope中的key值,我们可以在action中通过httpServletRequest.getAttribute("指定的name属性值")来获得这个actionForm; 当我们既配置了name又配置了attribute,那么actionForm存储在scope中的key值就采用attribute属性指定的值了,这时要通过httpServletRequest.getAttribute("指定的attribute属性值")来获得actionForm,此时通过httpServletRequest.getAttribute("指定的name属性值")是不能获得actionForm的。
所以,是否配置attribute属性就决定了actionForm存储在scope中的key值是采用name,还是采用attribute
public String getAttribute() {
//如果你没有设定attribute,那么struts 会把name的值拿过来用
if (this.attribute == null) {
return (this.name);
} else {
return (this.attribute);
}
}
为中name属性制定的ActionForm制定一个key关键字,这样就可根据scope属性指定的范围获取该ActionForm:
如:
则可通过request.getAttribute("user")获取"userForm"指定的ActionForm。
如果省略attribute属性,则可通过request.getAttribute("userForm")获取ActionForm
设置和ACTION关联的ActionForm Bean 在request或 session范围内的属性Key.如:Form Bean 存在于request范围内,名字为“MyBean”,那么用
request.getAttribut("MyBean")就可以返回它的实例。 这是孙姐在《精通STRUTS》中说的
就是把form以一个key形式放入request或session中(在配置文件的scope中指定范围,比如scope="request")
然后你可以用request.getAttribute("xxxForm");或者session...来得到它
struts的action中attribute属性是什么作用?
最新推荐文章于 2024-12-05 13:57:24 发布
本文详细介绍了在Struts框架中如何配置ActionForm及其在request或session中的存储方式。解释了name和attribute属性的作用,并提供了如何通过getAttribute方法获取ActionForm实例的具体示例。

2102

被折叠的 条评论
为什么被折叠?



