关于struts2 API 中InputConfig 内 methodName 和resultName的使用方法

转载于:http://chenchangqun11.iteye.com/blog/799306

 

对于methodName 和resultName的区别很迷惑,查了很多资料都不得其解

最后在API中找到答案

引用

(1)Marks a action method that if it's not validated by ValidationInterceptor then execute input method or input result.

Annotation usage: The InputConfig annotation can be applied at method level.

Annotation parameters:

Parameter  Required   Default  Notes
methodName no         (2)execute this method if specific
resultName no         (3)return this result if methodName not specific



(1)当验证方法没有通过时,改变默认返回的input视图
(2) 执行指定的方法
(3)返回result 如果methodName 没有指定

废话少说 上代码

Java代码
  1. public class StudentAction extends  ActionSupport {   
  2.    @InputConfig(methodName="input2",resultName="resultTest")   
  3.            
  4.     public String inputConfigTest2(){   
  5.                
  6.        return INPUT;   
  7.                
  8.         }   
  9.     public void validateInputConfigTest2(){   
  10.         addFieldError("ss""main validateInputConfigTest2");   
  11.     //validate方法在遇到 addFieldError方法时会自动返回input视图   
  12.            
  13.     }   
  14.         public String input2(){   
  15.                
  16.             return "test";   
  17.         }   
  18.   
  19. }  
public class StudentAction extends  ActionSupport {
   @InputConfig(methodName="input2",resultName="resultTest")
		
    public String inputConfigTest2(){
			
	   return INPUT;
			
		}
	public void validateInputConfigTest2(){
        addFieldError("ss", "main validateInputConfigTest2");
	//validate方法在遇到	addFieldError方法时会自动返回input视图
		
	}
		public String input2(){
			
			return "test";
		}

}


@InputConfig(methodName="input2",resultName="resultTest") 的作用是改变默认返回的input视图 API中可查
resultName只有在methodName没写如@InputConfig(resultName="resultTest") 时才起做用


Jsp页面

Java代码
  1. <%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签   
  2.   
  3. <body>   
  4.   <s:fielderror/>   
  5. inputconfig test   
  6. </body>  
<%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签

<body>
  <s:fielderror/>
inputconfig test
</body>



上述代码只写了少部分 请自己配置 Action 并测试
调用方法 如 http://localhost:8080/struts2test10/studentAction!inputConfigTest2

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值