Struts2中Action必须实现execute方法吗

struts2中action中是否须要实现execute方法呢?web

其实分两种状况:jsp


1)若是你的Action类是继承自ActionSupport或是BaseAction的话,确切的说是重写了execute方法,ActionSupport里的默认实现就是返回"success"视图。所以,你能够不实现execute方法,只要你的struts.xml里有"success"对应的result便可。xml

  1. <action name="doRevenuesMaintenance">  
  2.             <interceptor-ref name="novatar-webStack-baseparam">  
  3.                 <param name="security.actionType">PRIVATE</param>  
  4.             </interceptor-ref>  
  5.             <result name="success">incomeMaintenance.jsp</result>  
  6. < /action>  

 

这段代码中就是经过action的配置文件来控制跳转页面。在action的类中没有execute()方法重写。继承

 

2)若是你的Action类没有继承ActionSupport或是BaseAction的话,而你又没有在struts.xml中对应<action>标签中用method属性指定你本身的方法的话,默认就要找execute方法,这时是必需要实现execute方法的,不然Struts2会找不到对应的方法而报错。

不过,大部分状况下都是继承ActionSupport的(好比输入验证、文件上传等功能就要求必须继承)。还有,无论你写没写execute方法,仍是能够用<action>标签的method属性指定其余方法的。文件上传

相关文章
相关标签/搜索