Struts2學習筆記PreResultListener監聽器

來源:互聯網
上載者:User


1.說明
 
PreResultListener 是一個監聽器介面,它可以在 Action 完成控制處理之後,系統轉入實際的物理視圖之間被回調。
Struts2應用可以為Action、攔截器添加 PreResultListener 監聽器,添加PreResultListener 監聽器通過 ActionInvocation 的 addPreResultListener() 方法完成。 一旦為 Action 添加了PreResultListener 監聽器,該監聽器就可以在應用轉入實際物理視圖之前回調該監聽器的 beforeResult() 方法; 一旦為攔截器添加了 PreREsultListener 監聽器,該監聽器會對該攔截器所攔截的所有 Action 都起作用。
 

2.執行個體
 

 代碼如下 複製代碼
public class myAction extends Action
{
       public String execute()
       {
              ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
              invocation.addPreResultListener(new PreResultListener()
              {
                     public void beforeResult(ActionInvocation invacation, String resultCode)
                     {
                            //方法體內寫我們需要處理的監聽器商務邏輯
                            //上面的形參 resultCode 是前台發送的請求(即 Action 的邏輯名)
                     }
              });
       }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.