void

          struts2 注解配置

          1、web.xml 
          Java代碼  收藏代碼
          1. <!-- struts2 配置 -->  
          2.     <filter>  
          3.         <filter-name>struts2</filter-name>  
          4.         <filter-class>  
          5.             org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  
          6.         </filter-class>  
          7.         <init-param>  
          8.             <param-name>actionPackages</param-name>  
          9.             <param-value>com.yz.webapp.action</param-value>  
          10.         </init-param>  
          11.     </filter>  
          12.     <filter-mapping>  
          13.         <filter-name>struts2</filter-name>  
          14.         <url-pattern>/*</url-pattern>  
          15.     </filter-mapping>   

          struts.properties 
          Java代碼  收藏代碼
          1. #修改時重新加載  
          2. struts.configuration.xml.reload = true  
          3. #打印更多錯誤信息  
          4. struts.devMode = true  
          5. #注解掃描的包結尾名  
          6. struts.convention.package.locators = action  
          7. #映射擴展名  
          8. struts.action.extension = html  
          9. #結果資源所在路徑  
          10. #struts.convention.result.path = /WEB-INF/pages  

          2、action 類名上加注解 
          Java代碼  收藏代碼
          1. @Namespace("/ssi")  
          2. @ParentPackage("json-default")  
          3. @Action(value = "admin", results = {  
          4.         @Result(name = "success", location = "/WEB-INF/pages/admin.jsp"),  
          5.         @Result(name = "json", type = "json", params = { "excludeProperties","adminMgr" }) })  
          6. public class AdminAction extends BaseAction{}  

          多個Action 
          Java代碼  收藏代碼
          1. @Namespace("/msa")  
          2. @Result(name = "json", type = "json", params = { "excludeProperties",  
          3.     ".*Manager,.*\\.authorities,.*\\.roles,.*\\.fileCon" })  
          4. @Actions(value = {  
          5.     @Action(value = "foreignship", results = { @Result(name = "success", location = "foreignship/foreignship.jsp") }),  
          6.     @Action(value = "foreignshipsee", results = { @Result(name = "success", location = "foreignship/foreignshipsee.jsp") }) })  
          7. public class TMsaForeignShipArchivesAction extends BaseAction{}  


          在類方法上加注解 
          Java代碼  收藏代碼
          1. //@Action(value = "add", results = { @Result(name = "success", location = "/index.jsp") })  
          2. @Action(value = "save")  
          3. public String save() {  
          4.     try{  
          5.         adminMgr.insert("insertYz_admin", admin);  
          6.     }catch(Exception e){  
          7.         msg = e.toString();  
          8.         success = false;  
          9.     }  
          10.     return  this.SUCCESS;  
          11. }  

          posted on 2013-06-22 10:23 void 閱讀(424) 評論(0)  編輯  收藏 所屬分類: Struts2

          主站蜘蛛池模板: 通山县| 罗甸县| 集贤县| 桃江县| 永兴县| 苗栗市| 依安县| 册亨县| 乐东| 大同县| 商河县| 郓城县| 潼南县| 龙海市| 徐汇区| 黔南| 启东市| 隆林| 依安县| 亚东县| 保靖县| 黄浦区| 酒泉市| 澄迈县| 古交市| 庆城县| 莱西市| 武胜县| 大宁县| 明溪县| 广南县| 屯门区| 湟源县| 清水河县| 合江县| 清涧县| 海晏县| 安龙县| 贵阳市| 新和县| 历史|