研究action标签中attribute属性
* action标签中配置name属性
* 如果action标签中设置attribute="t"属性,又设置了name="loginForm"则mapping.getAttribute()中的参数是
action标签中配置的attribute="t"属性的值,如果使用loginForm取到的form是null
* 如果action标签中没有配置attribute属性,则mapping.getAttribute()中的参数是
Action标签中name属性的值
* 如果没有设置name属性,也没有配置attribute属性,则mapping.getAttribute()获取的值为null
注:没有name表示不需要ActionForm封装页面表单的数据
设置这个值的意思是将ActionForm存到某个域中供Action使用
request.setAttribute("loginForm",new LoginForm());
<form-bean name="loginForm" type="cn.itcast.web.form.LoginForm" /> <action path="/login" name="loginForm" scope="request" attribute="t" type="cn.itcast.web.action.LoginAction"></action> * 如果在action标签中没有配置name属性,而配置attribute是没有意义(attribute相当于给ActionForm取的别名,连ActionForm都没有,设置了别名就没意义了)* action标签中配置name属性
* 如果action标签中设置attribute="t"属性,又设置了name="loginForm"则mapping.getAttribute()中的参数是
action标签中配置的attribute="t"属性的值,如果使用loginForm取到的form是null
* 如果action标签中没有配置attribute属性,则mapping.getAttribute()中的参数是
Action标签中name属性的值
* 如果没有设置name属性,也没有配置attribute属性,则mapping.getAttribute()获取的值为null
注:没有name表示不需要ActionForm封装页面表单的数据
设置这个值的意思是将ActionForm存到某个域中供Action使用
request.setAttribute("loginForm",new LoginForm());
<action path="/login" name="loginForm" scope="request" attribute="t" type="cn.itcast.web.action.LoginAction"></action>
底层代码:从中可看出,如果attribute和name属性共存的时候,attribute有效,name属性是无效的
public String getAttribute() {
if (this.attribute == null) {
return (this.name);
} else {
return (this.attribute);
}
}
本文详细解析了Struts框架中action标签的attribute属性的作用及其与name属性的关系,阐述了不同配置情况下ActionForm如何被映射及存储。
1747

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



