`
baobeituping
  • 浏览: 1042669 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

struts2 annotation 验证采用自定义的跳转

 
阅读更多

对于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. }  

 

  1. <span style="font-size: medium;">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. }  
  20. </span>  

 


@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>  

 

  1. <span style="font-size: medium;"><%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签  
  2.   
  3. <body>  
  4.   <s:fielderror/>  
  5. inputconfig test  
  6. </body>  
  7.   
  8. </span>  



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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics