struts的action中attribute属性是什么作用?
2010-06-23 14:40
435 查看
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...来得到它
所以,是否配置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-config.xml中action元素的attribute属性的意义
- struts.xml文件中的action元素中的属性及其作用
- struts-config中action 的attribute属性与name属性
- struts-config.xml中 action 的attribute属性与name属性
- 阿翔编程学-struts-config.xml中action元素的attribute属性的意义
- Struts的配置文件struts-config.xml中action元素的parameter属性作用
- struts-config.xml中配置action的input属性的作用
- 关于struts-config里action元素里的attribute属性用途的理解
- struts-config中action的attribute属性与name属性的关系
- struts2.0框架中的action类实现ModelDriven的作用是什么?
- struts2中struts.xml中的action标签的method属性配置为"{1}"的时候是什么意味
- struts-config.xml中 action 的attribute属性与name属性
- struts action 属性
- html中data-uri和data-href的属性有什么作用
- struts笔记:struts action类中的get set 方法的作用
- Struts源码研究 - Action-Input属性篇
- Struts1 Action 属性详解
- SSH中 struts hibernate spring 各起什么作用
- html body 中onload 属性的作用是什么??
- bootstrap中的 form表单属性role="form"有什么作用?