Struts 2配布



 

  
  
  
  
  1. <package name="showForum" namespace="/" extends="struts-default"> 
  2.         <action name="showlist" method="{1}" class="forumAction"> 
  3.             <result name="success" >/showForumList.jsp</result> 
  4.             <result name="ERROR">/error.jsp</result> 
  5.         </action> 
  6. </package> 

注意:class=forumActionはspringと統合されているため、spirng beanのidです.
 
 

  
  
  
  
  1. package com.bbs.action.forum;  
  2.  
  3. import java.util.List;  
  4.  
  5. import com.bbs.pojo.Forum;  
  6. import com.bbs.services.ForumService;  
  7. import com.opensymphony.xwork2.ActionContext;  
  8.  
  9. public class ForumAction {  
  10.     private int fkid;  
  11.     private ForumService fSerive;  
  12.  
  13.     public int getFkid() {  
  14.         return fkid;  
  15.     }  
  16.  
  17.     public void setFkid(int fkid) {  
  18.         this.fkid = fkid;  
  19.     }  
  20.  
  21.     public ForumService getfSerive() {  
  22.         return fSerive;  
  23.     }  
  24.  
  25.     public void setfSerive(ForumService fSerive) {  
  26.         this.fSerive = fSerive;  
  27.     }  
  28.  
  29.     public String showForumList() {  
  30.         List<Forum> list = fSerive.getForumListByFkid(this.getFkid());  
  31.         ActionContext context = ActionContext.getContext();  
  32.         context.put("list", list);  
  33.         return "success";  
  34.     }  
  35. }  

リクエスト時に実行するメソッドがshowFormlist()である場合.
リクエストのアドレスは./actionName!methodName例:./showlits!/showForumList.action