close

 

這邊只是大致上記錄一下傾聽器的共通作用

就是在某些狀態下方便我們做新增、刪除、修改及記錄的動作

一來比方像Session 傾聽器 可以方便我們記錄登入數量

Ex:

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpSessionListener.html#sessionCreated(javax.servlet.http.HttpSessionEvent)  

(官網參考)

HttpSessiononListener

Interface HttpSessionListener (介面)

須實做兩個方法

Method Summary
 void sessionCreated(HttpSessionEvent se) 
          Receives notification that a session has been created.
 void sessionDestroyed(HttpSessionEvent se) 
          Receives notification that a session is about to be invalidated.

sessionCreated 

顧名思義就是Session建立時做的事

sessionDestroyed 

就是session 銷毀時會做甚麼事情

 

request.getSession().setAttribute("user", name);    // 這就是當我們建立session時

但即便我設了兩次 session 她仍然只會跑一次 sessionCreated

 

@WebListener
public class onSessionUserCounter implements HttpSessionListener {
   private static int counter;

public static int getCounter() {
   return counter;
}

@Override
public void sessionCreated(HttpSessionEvent se) {
   onSessionUserCounter.counter++;
}

@Override
public void sessionDestroyed(HttpSessionEvent se) {
      onSessionUserCounter.counter--;
   }
}

建立一個class 去計算當session的總數

 

而在web.xml 通常也會可以方便設定的方式

Ex: 

.....

   <listener>

         <listener-class> xxx.ccc.onSessionUserCounter  </listener-class>

   </listener>

.....

======================================

過濾器  Filter

概念: 

1.客戶只希望某些頁面給特定權限瀏覽

2.過濾有害自元

3.編碼更改....等等等

 

 太多了.....參考 servlet&jsp教學手冊第二版

 

 

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 JoshS 的頭像
    JoshS

    JoshS的部落格

    JoshS 發表在 痞客邦 留言(0) 人氣()