struts-config.xml文件中的action标签中的attributr属性详解

研究action标签中attribute属性
  <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);
        }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值